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

    1. <small id='QU55F'></small><noframes id='QU55F'>

      1. WHERE 子句中的条件顺序是否会影响 MySQL 性能?

        Does the order of conditions in a WHERE clause affect MySQL performance?(WHERE 子句中的条件顺序是否会影响 MySQL 性能?)

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

        <legend id='jHX5b'><style id='jHX5b'><dir id='jHX5b'><q id='jHX5b'></q></dir></style></legend>
        <tfoot id='jHX5b'></tfoot>

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

              <tbody id='jHX5b'></tbody>

              <bdo id='jHX5b'></bdo><ul id='jHX5b'></ul>

                • 本文介绍了WHERE 子句中的条件顺序是否会影响 MySQL 性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我有一个长而昂贵的查询,其中包含条件,搜索大量行.我还有一个特定条件,例如公司 ID,它将大大限制需要搜索的行数,将搜索范围从数十万缩小到数十个.

                  Say that I have a long, expensive query, packed with conditions, searching a large number of rows. I also have one particular condition, like a company id, that will limit the number of rows that need to be searched considerably, narrowing it down to dozens from hundreds of thousands.

                  我是否这样做对 MySQL 的性能有什么影响:

                  Does it make any difference to MySQL performance whether I do this:

                   SELECT * FROM clients WHERE 
                         (firstname LIKE :foo OR lastname LIKE :foo OR phone LIKE :foo) AND 
                         (firstname LIKE :bar OR lastname LIKE :bar OR phone LIKE :bar) AND 
                         company = :ugh
                  

                  或者这个:

                   SELECT * FROM clients WHERE 
                         company = :ugh AND
                         (firstname LIKE :foo OR lastname LIKE :foo OR phone LIKE :foo) AND 
                         (firstname LIKE :bar OR lastname LIKE :bar OR phone LIKE :bar) 
                  

                  推荐答案

                  不,顺序应该没有太大的不同.在查找与条件匹配的行时,会检查每一行的整个条件(通过布尔逻辑组合的所有子条件).

                  No, the order should not make a large difference. When finding which rows match the condition, the condition as a whole (all of the sub-conditions combined via boolean logic) is examined for each row.

                  一些智能数据库引擎会尝试猜测条件的哪些部分可以更快地评估(例如,不使用内置函数的东西)并首先评估那些,然后更复杂的(估计)元素被评估.不过,这是由数据库引擎决定的,而不是 SQL.

                  Some intelligent DB engines will attempt to guess which parts of the condition can be evaluated faster (for instance, things that don't use built-in functions) and evaluate those first, and more complex (estimatedly) elements get evaluated later. This is something determined by the DB engine though, not the SQL.

                  这篇关于WHERE 子句中的条件顺序是否会影响 MySQL 性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)

                      <tbody id='WiUbV'></tbody>

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

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