久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    1. <tfoot id='QczFk'></tfoot>

      <small id='QczFk'></small><noframes id='QczFk'>

        <bdo id='QczFk'></bdo><ul id='QczFk'></ul>
      <legend id='QczFk'><style id='QczFk'><dir id='QczFk'><q id='QczFk'></q></dir></style></legend>

        <i id='QczFk'><tr id='QczFk'><dt id='QczFk'><q id='QczFk'><span id='QczFk'><b id='QczFk'><form id='QczFk'><ins id='QczFk'></ins><ul id='QczFk'></ul><sub id='QczFk'></sub></form><legend id='QczFk'></legend><bdo id='QczFk'><pre id='QczFk'><center id='QczFk'></center></pre></bdo></b><th id='QczFk'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='QczFk'><tfoot id='QczFk'></tfoot><dl id='QczFk'><fieldset id='QczFk'></fieldset></dl></div>

        為什么 IN 條件比“="慢?在 sql 中?

        Why would an IN condition be slower than quot;=quot; in sql?(為什么 IN 條件比“=慢?在 sql 中?)

            <small id='a3r75'></small><noframes id='a3r75'>

            <tfoot id='a3r75'></tfoot>
          1. <i id='a3r75'><tr id='a3r75'><dt id='a3r75'><q id='a3r75'><span id='a3r75'><b id='a3r75'><form id='a3r75'><ins id='a3r75'></ins><ul id='a3r75'></ul><sub id='a3r75'></sub></form><legend id='a3r75'></legend><bdo id='a3r75'><pre id='a3r75'><center id='a3r75'></center></pre></bdo></b><th id='a3r75'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='a3r75'><tfoot id='a3r75'></tfoot><dl id='a3r75'><fieldset id='a3r75'></fieldset></dl></div>

              <tbody id='a3r75'></tbody>

            • <bdo id='a3r75'></bdo><ul id='a3r75'></ul>

                  <legend id='a3r75'><style id='a3r75'><dir id='a3r75'><q id='a3r75'></q></dir></style></legend>
                1. 本文介紹了為什么 IN 條件比“="慢?在 sql 中?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  檢查問題此 SELECT 查詢需要 180 秒才能完成(檢查問題本身的評(píng)論).
                  IN只能與一個(gè)值進(jìn)行比較,但時(shí)間差異仍然很大.
                  為什么會(huì)這樣?

                  解決方案

                  總結(jié):這是一個(gè) MySQL 中的>已知問題,并在 MySQL 5.6.x 中修復(fù).該問題是由于使用 IN 的子查詢被錯(cuò)誤地識(shí)別為依賴子查詢而不是獨(dú)立子查詢時(shí)缺少優(yōu)化.

                  <小時(shí)>

                  當(dāng)您對(duì)原始查詢運(yùn)行 EXPLAIN 時(shí),它會(huì)返回:

                  <前>1 'PRIMARY' 'question_law_version' 'ALL' '' '' '' '' 10148 '使用哪里'2 'DEPENDENT SUBQUERY' 'question_law_version' 'ALL' '' '' '' '' 10148 '使用地點(diǎn)'3 'DEPENDENT SUBQUERY' 'question_law' 'ALL' '' '' '' '' 10040 '使用哪里'

                  當(dāng)您將 IN 更改為 = 時(shí),您會(huì)得到:

                  <前>1 'PRIMARY' 'question_law_version' 'ALL' '' '' '' '' 10148 '使用哪里'2 'SUBQUERY' 'question_law_version' 'ALL' '' '' '' '' 10148 '使用地點(diǎn)'3 'SUBQUERY' 'question_law' 'ALL' '' '' '' '' 10040 '使用地點(diǎn)'

                  每個(gè)依賴子查詢?cè)谒牟樵冎械拿恳恍羞\(yùn)行一次,而子查詢只運(yùn)行一次.當(dāng)存在可以轉(zhuǎn)換為連接的條件時(shí),MySQL 有時(shí)可以優(yōu)化依賴子查詢,但這里并非如此.

                  現(xiàn)在這當(dāng)然留下了為什么 MySQL 認(rèn)為 IN 版本需要是依賴子查詢的問題.我制作了一個(gè)簡(jiǎn)化版的查詢來幫助調(diào)查這個(gè)問題.我創(chuàng)建了兩個(gè)表foo"和bar",其中前者只包含一個(gè) id 列,后者包含一個(gè) id 和一個(gè) foo id(盡管我沒有創(chuàng)建外鍵約束).然后我用 1000 行填充了兩個(gè)表:

                  CREATE TABLE foo (id INT PRIMARY KEY NOT NULL);CREATE TABLE bar (id INT PRIMARY KEY, foo_id INT NOT NULL);-- 在每個(gè)表中填充 1000 行選擇 ID從 foo在哪里(選擇最大(foo_id)發(fā)件人欄);

                  這個(gè)簡(jiǎn)化的查詢有和之前一樣的問題——內(nèi)部選擇被當(dāng)作依賴子查詢處理,沒有進(jìn)行優(yōu)化,導(dǎo)致內(nèi)部查詢每行運(yùn)行一次.查詢幾乎需要一秒鐘才能運(yùn)行.再次將 IN 更改為 = 幾乎可以立即運(yùn)行查詢.

                  我用來填充表格的代碼如下,以防有人希望重現(xiàn)結(jié)果.

                  CREATE TABLE 填充符 (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT) 引擎=內(nèi)存;分隔符 $$創(chuàng)建程序 prc_filler(cnt INT)開始聲明 _cnt INT;設(shè)置_cnt = 1;而 _cnt <= cnt 做插入INTO填料選擇_cnt;SET _cnt = _cnt + 1;結(jié)束時(shí);結(jié)尾$$分隔符;呼叫 prc_filler(1000);INSERT foo SELECT id FROM fills;INSERT bar SELECT id, id FROM 填充符;

                  Check the question This SELECT query takes 180 seconds to finish (check the comments on the question itself).
                  The IN get to be compared against only one value, but still the time difference is enormous.
                  Why is it like that?

                  解決方案

                  Summary: This is a known problem in MySQL and was fixed in MySQL 5.6.x. The problem is due to a missing optimization when a subquery using IN is incorrectly indentified as dependent subquery instead of an independent subquery.


                  When you run EXPLAIN on the original query it returns this:

                  1  'PRIMARY'             'question_law_version'  'ALL'  ''  ''  ''  ''  10148  'Using where'
                  2  'DEPENDENT SUBQUERY'  'question_law_version'  'ALL'  ''  ''  ''  ''  10148  'Using where'
                  3  'DEPENDENT SUBQUERY'  'question_law'          'ALL'  ''  ''  ''  ''  10040  'Using where'
                  

                  When you change IN to = you get this:

                  1  'PRIMARY'   'question_law_version'  'ALL'  ''  ''  ''  ''  10148  'Using where'
                  2  'SUBQUERY'  'question_law_version'  'ALL'  ''  ''  ''  ''  10148  'Using where'
                  3  'SUBQUERY'  'question_law'          'ALL'  ''  ''  ''  ''  10040  'Using where'
                  

                  Each dependent subquery is run once per row in the query it is contained in, whereas the subquery is run only once. MySQL can sometimes optimize dependent subqueries when there is a condition that can be converted to a join but here that is not the case.

                  Now this of course leaves the question of why MySQL believes that the IN version needs to be a dependent subquery. I have made a simplified version of the query to help investigate this. I created two tables 'foo' and 'bar' where the former contains only an id column, and the latter contains both an id and a foo id (though I didn't create a foreign key constraint). Then I populated both tables with 1000 rows:

                  CREATE TABLE foo (id INT PRIMARY KEY NOT NULL);
                  CREATE TABLE bar (id INT PRIMARY KEY, foo_id INT NOT NULL);
                  
                  -- populate tables with 1000 rows in each
                  
                  SELECT id
                  FROM foo
                  WHERE id IN
                  (
                      SELECT MAX(foo_id)
                      FROM bar
                  );
                  

                  This simplified query has the same problem as before - the inner select is treated as a dependent subquery and no optimization is performed, causing the inner query to be run once per row. The query takes almost one second to run. Changing the IN to = again allows the query to run almost instantly.

                  The code I used to populate the tables is below, in case anyone wishes to reproduce the results.

                  CREATE TABLE filler (
                          id INT NOT NULL PRIMARY KEY AUTO_INCREMENT
                  ) ENGINE=Memory;
                  
                  DELIMITER $$
                  
                  CREATE PROCEDURE prc_filler(cnt INT)
                  BEGIN
                          DECLARE _cnt INT;
                          SET _cnt = 1;
                          WHILE _cnt <= cnt DO
                                  INSERT
                                  INTO    filler
                                  SELECT  _cnt;
                                  SET _cnt = _cnt + 1;
                          END WHILE;
                  END
                  $$
                  
                  DELIMITER ;
                  
                  CALL prc_filler(1000);
                  
                  INSERT foo SELECT id FROM filler;
                  INSERT bar SELECT id, id FROM filler;
                  

                  這篇關(guān)于為什么 IN 條件比“="慢?在 sql 中?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數(shù)根據(jù) N 個(gè)先前值來決定接下來的 N 個(gè)行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達(dá)式的結(jié)果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數(shù)的 ignore 選項(xiàng)是忽略整個(gè)事務(wù)還是只是有問題的行?) - IT屋-程序員軟件開發(fā)技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時(shí)出錯(cuò),使用 for 循環(huán)數(shù)組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調(diào)用 o23.load 時(shí)發(fā)生錯(cuò)誤 沒有合適的驅(qū)動(dòng)程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數(shù)據(jù)庫表作為 Spark 數(shù)據(jù)幀讀取?)
                    • <tfoot id='E5Hgp'></tfoot>
                        <tbody id='E5Hgp'></tbody>
                      <i id='E5Hgp'><tr id='E5Hgp'><dt id='E5Hgp'><q id='E5Hgp'><span id='E5Hgp'><b id='E5Hgp'><form id='E5Hgp'><ins id='E5Hgp'></ins><ul id='E5Hgp'></ul><sub id='E5Hgp'></sub></form><legend id='E5Hgp'></legend><bdo id='E5Hgp'><pre id='E5Hgp'><center id='E5Hgp'></center></pre></bdo></b><th id='E5Hgp'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='E5Hgp'><tfoot id='E5Hgp'></tfoot><dl id='E5Hgp'><fieldset id='E5Hgp'></fieldset></dl></div>
                        • <bdo id='E5Hgp'></bdo><ul id='E5Hgp'></ul>

                          <small id='E5Hgp'></small><noframes id='E5Hgp'>

                          <legend id='E5Hgp'><style id='E5Hgp'><dir id='E5Hgp'><q id='E5Hgp'></q></dir></style></legend>

                            主站蜘蛛池模板: 国产精品久久久久aaaa九色 | 国产999精品久久久影片官网 | 日韩欧美二区 | 成人超碰在线 | 日本精品久久久久久久 | 九九福利 | 国产精品久久久久久久久久久久久 | 久久专区 | 国产视频中文字幕在线观看 | 成人性视频免费网站 | 亚洲第一av网站 | 特黄级国产片 | 美女福利视频一区 | 91人人澡人人爽 | 91网站视频在线观看 | 丁香五月缴情综合网 | 国产小网站 | 福利视频日韩 | 日韩欧美在线播放 | 精品久久久久一区二区国产 | 亚洲91视频| 成人精品一区二区 | 亚洲不卡一 | 午夜丁香视频在线观看 | 国产精品日韩一区二区 | 久久精品男人的天堂 | 中文字幕中文字幕 | 精品国产乱码一区二区三区a | 国产永久免费 | 欧美日韩一卡 | 91视频正在播放 | 成人av在线播放 | 午夜小视频免费观看 | 色网站视频 | 色婷婷综合在线观看 | 中文字幕不卡在线88 | 狠狠av| 免费视频99| 青青草av| 久久日韩精品 | 综合自拍 |