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

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

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

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

      此 SELECT 查询需要 180 秒才能完成

      This SELECT query takes 180 seconds to finish(此 SELECT 查询需要 180 秒才能完成)
        <tfoot id='yt3rB'></tfoot>
      • <i id='yt3rB'><tr id='yt3rB'><dt id='yt3rB'><q id='yt3rB'><span id='yt3rB'><b id='yt3rB'><form id='yt3rB'><ins id='yt3rB'></ins><ul id='yt3rB'></ul><sub id='yt3rB'></sub></form><legend id='yt3rB'></legend><bdo id='yt3rB'><pre id='yt3rB'><center id='yt3rB'></center></pre></bdo></b><th id='yt3rB'></th></span></q></dt></tr></i><div id='yt3rB'><tfoot id='yt3rB'></tfoot><dl id='yt3rB'><fieldset id='yt3rB'></fieldset></dl></div>
        <legend id='yt3rB'><style id='yt3rB'><dir id='yt3rB'><q id='yt3rB'></q></dir></style></legend>

        • <bdo id='yt3rB'></bdo><ul id='yt3rB'></ul>
            1. <small id='yt3rB'></small><noframes id='yt3rB'>

                <tbody id='yt3rB'></tbody>

                本文介绍了此 SELECT 查询需要 180 秒才能完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                更新:

                只是在更显眼的地方提及它.当我将 IN 更改为 = 时,查询执行时间从 180 秒减少到 0.00008 秒.可笑的速度差异.

                Just to mention it on a more visible place. When I changed IN for =, the query execution time went from 180 down to 0.00008 seconds. Ridiculous speed difference.

                这个 SQL 查询需要 180 秒才能完成!这怎么可能?有没有办法优化它以使其更快?

                This SQL query takes 180 seconds to finish! How is that possible? is there a way to optimize it to be faster?

                SELECT IdLawVersionValidFrom 
                FROM question_law_version 
                WHERE IdQuestionLawVersion IN 
                  (
                  SELECT MAX(IdQuestionLawVersion) 
                  FROM question_law_version 
                  WHERE IdQuestionLaw IN 
                    (
                    SELECT MIN(IdQuestionLaw) 
                    FROM question_law 
                    WHERE IdQuestion=236 AND IdQuestionLaw>63
                    )
                  )
                

                每个表中只有大约 5000 行,所以速度应该不会太慢.

                There are only about 5000 rows in each table so it shouldn't be so slow.

                推荐答案

                (发布我的评论作为答案,显然它确实有所作为!)

                (Posting my comment as an answer as apparently it did make a difference!)

                如果您更改 IN 有什么不同=?

                Any difference if you change the IN to =?

                如果有人想进一步调查这个问题,我刚刚做了一个测试,发现它很容易重现.

                If anyone wants to investigate this further I've just done a test and found it very easy to reproduce.

                创建表

                CREATE TABLE `filler` (
                  `id` int(11) NOT NULL AUTO_INCREMENT,
                  PRIMARY KEY (`id`)
                ) 
                

                创建过程

                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
                

                填充表

                  call prc_filler(5000)
                

                查询 1

                SELECT id 
                FROM filler 
                WHERE id =  (SELECT MAX(id) FROM filler  WHERE id =   
                 ( SELECT MIN(id) 
                    FROM filler
                    WHERE id between 2000 and 3000
                    )
                  )
                

                Equals 解释输出 http://img689.imageshack.us/img689/5592/equals.png

                查询 2(同样的问题)

                Query 2 (same problem)

                SELECT id 
                FROM filler 
                WHERE id in  (SELECT MAX(id) FROM filler  WHERE id in   
                 ( SELECT MIN(id) 
                    FROM filler
                    WHERE id between 2000 and 3000
                    )
                  )
                

                解释输出 http://img291.imageshack.us/img291/8129/52037513.png

                这篇关于此 SELECT 查询需要 180 秒才能完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Building a comma separated list?(建立一个逗号分隔的列表?)
                Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)

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

              2. <small id='Eul0g'></small><noframes id='Eul0g'>

                1. <tfoot id='Eul0g'></tfoot><legend id='Eul0g'><style id='Eul0g'><dir id='Eul0g'><q id='Eul0g'></q></dir></style></legend>

                  • <bdo id='Eul0g'></bdo><ul id='Eul0g'></ul>
                      <tbody id='Eul0g'></tbody>