• <tfoot id='8o5cH'></tfoot>

    1. <legend id='8o5cH'><style id='8o5cH'><dir id='8o5cH'><q id='8o5cH'></q></dir></style></legend>
        <bdo id='8o5cH'></bdo><ul id='8o5cH'></ul>
    2. <small id='8o5cH'></small><noframes id='8o5cH'>

        <i id='8o5cH'><tr id='8o5cH'><dt id='8o5cH'><q id='8o5cH'><span id='8o5cH'><b id='8o5cH'><form id='8o5cH'><ins id='8o5cH'></ins><ul id='8o5cH'></ul><sub id='8o5cH'></sub></form><legend id='8o5cH'></legend><bdo id='8o5cH'><pre id='8o5cH'><center id='8o5cH'></center></pre></bdo></b><th id='8o5cH'></th></span></q></dt></tr></i><div id='8o5cH'><tfoot id='8o5cH'></tfoot><dl id='8o5cH'><fieldset id='8o5cH'></fieldset></dl></div>
      1. MySQL“输入"使用子查询查询非常慢,但使用显式值查询速度很快

        时间:2023-06-26
        <i id='uUPFg'><tr id='uUPFg'><dt id='uUPFg'><q id='uUPFg'><span id='uUPFg'><b id='uUPFg'><form id='uUPFg'><ins id='uUPFg'></ins><ul id='uUPFg'></ul><sub id='uUPFg'></sub></form><legend id='uUPFg'></legend><bdo id='uUPFg'><pre id='uUPFg'><center id='uUPFg'></center></pre></bdo></b><th id='uUPFg'></th></span></q></dt></tr></i><div id='uUPFg'><tfoot id='uUPFg'></tfoot><dl id='uUPFg'><fieldset id='uUPFg'></fieldset></dl></div>

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

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

                    <tbody id='uUPFg'></tbody>

                • <tfoot id='uUPFg'></tfoot>
                  <legend id='uUPFg'><style id='uUPFg'><dir id='uUPFg'><q id='uUPFg'></q></dir></style></legend>
                  本文介绍了MySQL“输入"使用子查询查询非常慢,但使用显式值查询速度很快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 MySQL 查询(Ubu 10.04、Innodb、Core i7、16Gb RAM、SSD 驱动器、优化的 MySQL 参数):

                  I have a MySQL query (Ubu 10.04,Innodb, Core i7, 16Gb RAM, SSD drives, MySQL params optimized):

                  SELECT
                  COUNT(DISTINCT subscriberid)
                  FROM
                  em_link_data
                  WHERE
                  linkid in (SELECT l.id FROM em_link l WHERE l.campaignid = '2900' AND l.link != 'open')
                  

                  表 em_link_data 大约有 700 万行,em_link 有几千行.完成此查询大约需要 18 秒.但是,如果我替换结果子查询并执行以下操作:

                  The table em_link_data has about 7million rows, em_link has a few thousand. This query will take about 18 seconds to complete. However, if I substitute the results of the subquery and do this:

                  SELECT
                  COUNT(DISTINCT subscriberid)
                  FROM
                  em_link_data
                  WHERE
                  linkid in (24899,24900,24901,24902);
                  

                  那么查询将在不到 1 毫秒内运行.子查询单独运行不到1ms,列linkid被索引.

                  then the query will run in less than 1 millisecond. The subquery alone runs in less than 1ms, the column linkid is indexed.

                  如果我将查询重写为连接,也少于 1 毫秒.为什么带有子查询的IN"查询如此之慢,而其中的值为何如此之快?我无法重写查询(购买软件),所以我希望有一些调整或提示来加速这个查询!任何帮助表示赞赏.

                  If I rewrite the query as a join, also less than 1ms. Why is a "IN" query so slow with a subquery in it and why so fast with values in it? I can't rewrite the query (bought software) so I was hoping there is some tweak or hint to speedup this query! Any help is appreciated.

                  推荐答案

                  子查询在您每次评估它们时都会执行(无论如何在 MySQL 中,并非所有 RDBMS),即您基本上运行了 700 万个查询!如果可能,使用 JOIN 会将其减少到 1.即使添加索引提高了它们的性能,您仍然在运行它们.

                  Subqueries execute every time you evaluate them (in MySQL anyway, not all RDBMSes), i.e. you're basically running 7 million queries! Using a JOIN, if possible, will reduce this to 1. Even if adding indexing improves performance of those, you're still running them.

                  这篇关于MySQL“输入"使用子查询查询非常慢,但使用显式值查询速度很快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:MySQL:LAST_INSERT_ID() 返回 0 下一篇:如何在mysql中获取两个日期之间的月份列表

                  相关文章

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

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

                    <tfoot id='Ep8ue'></tfoot>
                  1. <small id='Ep8ue'></small><noframes id='Ep8ue'>

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