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

  • <legend id='JtuSs'><style id='JtuSs'><dir id='JtuSs'><q id='JtuSs'></q></dir></style></legend>

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

        MYSQL OR 与 IN 性能

        时间:2023-08-18
          <tbody id='pRgmd'></tbody>
        <legend id='pRgmd'><style id='pRgmd'><dir id='pRgmd'><q id='pRgmd'></q></dir></style></legend>
        • <small id='pRgmd'></small><noframes id='pRgmd'>

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

                • 本文介绍了MYSQL OR 与 IN 性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想知道以下在性能方面是否有任何差异

                  I am wondering if there is any difference in regards to performance between the following

                  SELECT ... FROM ... WHERE someFIELD IN(1,2,3,4)
                  
                  SELECT ... FROM ... WHERE someFIELD between  0 AND 5
                  
                  SELECT ... FROM ... WHERE someFIELD = 1 OR someFIELD = 2 OR someFIELD = 3 ... 
                  

                  或者 MySQL 会像编译器优化代码一样优化 SQL 吗?

                  or will MySQL optimize the SQL in the same way compilers will optimize code ?

                  AND 更改为 OR 的原因在评论中说明.

                  Changed the AND's to OR's for the reason stated in the comments.

                  推荐答案

                  接受的答案没有解释原因.

                  The accepted answer doesn't explain the reason.

                  以下引用自高性能 MySQL,第 3 版.

                  Below are quoted from High Performance MySQL, 3rd Edition.

                  在许多数据库服务器中,IN() 只是多个 OR 子句的同义词,因为两者在逻辑上是等价的.在 MySQL 中不是这样,它对 IN() 列表中的值进行排序并使用快速二进制搜索来查看某个值是否在列表中.这是列表大小的 O(Log n),而等效的一系列 OR 子句在列表的大小上是 O(n)(即,对于大列表要慢得多)

                  In many database servers, IN() is just a synonym for multiple OR clauses, because the two are logically equivalent. Not so in MySQL, which sorts the values in the IN() list and uses a fast binary search to see whether a value is in the list. This is O(Log n) in the size of the list, whereas an equivalent series of OR clauses is O(n) in the size of the list (i.e., much slower for large lists)

                  这篇关于MYSQL OR 与 IN 性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:'SELECT' 语句中的 'IF' - 根据列值选择 下一篇:如何使用某些前缀使 MySQL 表主键自动递增

                  相关文章

                  最新文章

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

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

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