久久久久久久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 中?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

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

                  解決方案

                  總結:這是一個 MySQL 中的>已知問題,并在 MySQL 5.6.x 中修復.該問題是由于使用 IN 的子查詢被錯誤地識別為依賴子查詢而不是獨立子查詢時缺少優化.

                  <小時>

                  當您對原始查詢運行 EXPLAIN 時,它會返回:

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

                  當您將 IN 更改為 = 時,您會得到:

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

                  每個依賴子查詢在它所包含的查詢中的每一行運行一次,而子查詢只運行一次.當存在可以轉換為連接的條件時,MySQL 有時可以優化依賴子查詢,但這里并非如此.

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

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

                  這個簡化的查詢有和之前一樣的問題——內部選擇被當作依賴子查詢處理,沒有進行優化,導致內部查詢每行運行一次.查詢幾乎需要一秒鐘才能運行.再次將 IN 更改為 = 幾乎可以立即運行查詢.

                  我用來填充表格的代碼如下,以防有人希望重現結果.

                  CREATE TABLE 填充符 (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT) 引擎=內存;分隔符 $$創建程序 prc_filler(cnt INT)開始聲明 _cnt INT;設置_cnt = 1;而 _cnt <= cnt 做插入INTO填料選擇_cnt;SET _cnt = _cnt + 1;結束時;結尾$$分隔符;呼叫 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;
                  

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

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

                  相關文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數根據 N 個先前值來決定接下來的 N 個行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數的 ignore 選項是忽略整個事務還是只是有問題的行?) - IT屋-程序員軟件開發技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調用 o23.load 時發生錯誤 沒有合適的驅動程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數據庫表作為 Spark 數據幀讀取?)
                    • <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>

                            主站蜘蛛池模板: 国产a级黄色录像 | 免费小视频在线观看 | 99reav| 伊人免费在线观看高清 | 久久最新精品 | 欧美久久久久久久久中文字幕 | 亚洲高清视频在线 | 在线亚洲欧美 | 亚洲国产视频一区二区 | 一级片av | 成人18亚洲xxoo | 成人不卡 | 久一精品 | 69av片| 日本一区视频在线观看 | 狠狠草视频 | 国产一区二区在线观看视频 | 国产精品国产三级国产a | 日韩午夜一区二区三区 | 国产精品久久毛片av大全日韩 | 精品国产91久久久久久 | 国产在线对白 | 国产成人免费视频网站视频社区 | 中文字幕乱码一区二区三区 | 一区二区精品 | 婷婷激情在线 | www在线视频 | 国产成人精品久久二区二区 | 超碰日本| 免费一区二区三区在线视频 | 国产一在线 | 国产在线视频一区二区董小宛性色 | 久久国产精品久久国产精品 | 一区二区三区视频在线观看 | 国外成人在线视频网站 | 91网站在线观看视频 | 91免费看片神器 | 国精久久| 一级毛片免费完整视频 | 一区二区三区在线 | 嫩草视频在线免费观看 |