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

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

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

        哪个 SQL 查询更好,MATCH AGAINST 还是 LIKE?

        时间:2023-05-24
      3. <small id='S84Ni'></small><noframes id='S84Ni'>

            <bdo id='S84Ni'></bdo><ul id='S84Ni'></ul>
            <tfoot id='S84Ni'></tfoot>

            <i id='S84Ni'><tr id='S84Ni'><dt id='S84Ni'><q id='S84Ni'><span id='S84Ni'><b id='S84Ni'><form id='S84Ni'><ins id='S84Ni'></ins><ul id='S84Ni'></ul><sub id='S84Ni'></sub></form><legend id='S84Ni'></legend><bdo id='S84Ni'><pre id='S84Ni'><center id='S84Ni'></center></pre></bdo></b><th id='S84Ni'></th></span></q></dt></tr></i><div id='S84Ni'><tfoot id='S84Ni'></tfoot><dl id='S84Ni'><fieldset id='S84Ni'></fieldset></dl></div>
            • <legend id='S84Ni'><style id='S84Ni'><dir id='S84Ni'><q id='S84Ni'></q></dir></style></legend>
                    <tbody id='S84Ni'></tbody>
                1. 本文介绍了哪个 SQL 查询更好,MATCH AGAINST 还是 LIKE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  要在数据库中搜索在任何列foo_desc"和bar_desc"中同时具有关键字foo"和bar"的行,我会执行以下操作:

                  To search the database for rows that have both keywords "foo" AND "bar" in any of the columns "foo_desc" and "bar_desc", I would do something like:

                  SELECT * 
                  FROM t1 
                  WHERE MATCH (t1.foo_desc, t2.bar_desc) AGAINST ('+foo* +bar*' IN BOOLEAN MODE)
                  

                  SELECT * 
                  FROM t1 
                  WHERE (CONCAT(t1.foo_desc, t2.bar_desc) LIKE '%foo%') AND (CONCAT(t1.foo_desc, t2.bar_desc) LIKE '%bar%')
                  

                  我预计最后一个查询的缺点是性能.

                  I expect the downside of the last query is performance.

                  好处是 LIKE 查询找到了xxfoo",而 MATCH AGAINST 没有找到.

                  The upside is that the LIKE query finds 'xxfoo' where MATCH AGAINST does not.

                  哪个是首选或有更好的解决方案?

                  Which is the preferred one or is there a better solution?

                  推荐答案

                  更新

                  MySQL 5.6 及更高版本开始,InnoDB 表支持 Match... Against.

                  Update

                  As of MySQL 5.6 and later, InnoDB tables supports Match... Against.

                  第一个好多更好.在 MyISAM 表上,它将对这些列使用全文索引.另一个将进行全表扫描,对每一行进行连接,然后进行比较.

                  The first is much better. On MyISAM tables it will use a full text index against those columns. The other will do a full table scan doing a concat on every row and then a comparison.

                  LIKE 只有在你反对时才有效:

                  LIKE is only efficient if you're doing it against:

                  • 一列(不是函数的结果,除非您的特定数据库供应商支持函数索引——例如 Oracle——并且您正在使用它们);
                  • 列的开头(即 LIKE 'blah%' 而不是 LIKE '%blah%');和
                  • 已编入索引的列.

                  如果其中任何一个条件不成立,SQL 引擎执行查询的唯一方法就是执行全表扫描.这可以在大约 10-20,000 行下使用.然而,除此之外,它很快就变得无法使用.

                  If any one of those conditions are not true the only way for the SQL engine to execute the query is by doing a full table scan. This can be usable under about 10-20 thousand rows. Beyond that it quickly becomes unusable however.

                  注意: MySQL 上 MATCH 的一个问题是它似乎只匹配整个单词,因此搜索 'bla' 不会匹配值为 'blah' 的列,但是搜索bla*"会.

                  Note: One problem with MATCH on MySQL is that it seems to only match against whole words so a search for 'bla' won't match a column with a value of 'blah', but a search for 'bla*' will.

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

                  上一篇:将自动递增 ID 添加到现有表? 下一篇:如何使用GROUP BY获取每个组中的最新记录?

                  相关文章

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

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

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