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

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

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

      1. 哪个更快——INSTR 还是 LIKE?

        时间:2023-06-26

          <tbody id='cNNBV'></tbody>
        <legend id='cNNBV'><style id='cNNBV'><dir id='cNNBV'><q id='cNNBV'></q></dir></style></legend>

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

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

                <tfoot id='cNNBV'></tfoot>
                1. 本文介绍了哪个更快——INSTR 还是 LIKE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果您的目标是测试某个字符串是否存在于 MySQL 列(类型为varchar"、text"、blob"等)中,以下哪个更快/更有效/更好用,以及为什么?

                  If your goal is to test if a string exists in a MySQL column (of type 'varchar', 'text', 'blob', etc) which of the following is faster / more efficient / better to use, and why?

                  或者,是否有其他方法可以胜过其中任何一个?

                  Or, is there some other method that tops either of these?

                  INSTR( columnname, 'mystring' ) > 0
                  

                  对比

                  columnname LIKE '%mystring%'
                  

                  推荐答案

                  FULLTEXT 搜索绝对会更快,正如 kibibu 在上面的评论中指出的那样.

                  FULLTEXT searches are absolutely going to be faster, as kibibu noted in the comments above.

                  不过:

                  mysql> select COUNT(ID) FROM table WHERE INSTR(Name,'search') > 0;
                  +-----------+
                  | COUNT(ID) |
                  +-----------+
                  |     40735 | 
                  +-----------+
                  1 row in set (5.54 sec)
                  
                  mysql> select COUNT(ID) FROM table WHERE Name LIKE '%search%';
                  +-----------+
                  | COUNT(ID) |
                  +-----------+
                  |     40735 | 
                  +-----------+
                  1 row in set (5.54 sec)
                  

                  在我的测试中,它们的表现完全相同.它们都不区分大小写,并且通常执行全表扫描,这是处理高性能 MySQL 时的一般禁忌.

                  In my tests, they perform exactly the same. They are both case-insensitive, and generally they perform full-table scans, a general no-no when dealing with high-performance MySQL.

                  除非您对索引列进行前缀搜索:

                  Unless you are doing a prefix search on an indexed column:

                  mysql> select COUNT(ID) FROM table WHERE Name LIKE 'search%';
                  +-----------+
                  | COUNT(ID) |
                  +-----------+
                  |         7 | 
                  +-----------+
                  1 row in set (3.88 sec)
                  

                  在这种情况下,只有后缀通配符的 LIKE 要快得多.

                  In which case, the LIKE with only a suffix wildcard is much faster.

                  这篇关于哪个更快——INSTR 还是 LIKE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:何时在 MySQL 表中使用 NULL 下一篇:薛定谔 MySQL 表:存在,但不存在

                  相关文章

                  <tfoot id='rwFhL'></tfoot>

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

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

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