【问题标题】:difference between these 2 queries这两个查询之间的区别
【发布时间】:2014-06-02 12:04:10
【问题描述】:

我正在运行 2 个查询,应该会显示相同的结果,

第一个查询:

SELECT count( id ) AS cv FROM table_name WHERE field_name LIKE '%êêê01, word02, word03%'

第二次查询:

SELECT count( id ) AS cv FROM table_name WHERE match(field_name) against('êêê01, word02, word03')

但是第一个显示的行比第二个多,有人可以告诉我为什么吗?

我在这个字段上使用全文索引,

谢谢。

【问题讨论】:

    标签: mysql


    【解决方案1】:

    我做了一个快速的research,下面的引用应该回答你的问题:

    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'.

    documentation for match中也有描述

    By default, the MATCH() function performs a natural language search for a string against a text collection. A collection is a set of one or more columns included in a FULLTEXT index. The search string is given as the argument to AGAINST(). For each row in the table, MATCH() returns a relevance value; that is, a similarity measure between the search string and the text in that row in the columns named in the MATCH() list.

    同时like 更“强大”,因为它可以查看单个字符:

    Per the SQL standard, LIKE performs matching on a per-character basis, thus it can produce results different from the = comparison operator:

    这就解释了为什么like 返回的结果比match 多。

    【讨论】:

    • 有办法解决吗?
    • @user3466310 不。如果您希望您的查询能够找到与您的索引字符串有些相关的任何字符串,那么您必须坚持使用likematch 只是一个完全不同的操作,它允许您匹配有限的字符串集。很难说你所说的“修复”是什么意思,因为他们都在做它的工作,他们的工作根本不一样。
    • 嗯,嗯,我用 match 因为它比 like 更快,因为我有一个有 2800 万行的表,你知道在这样的表中搜索的一些解决方案吗?跨度>
    • @user3466310 如果您真的需要能够按单个字符进行搜索,那么不,恐怕不需要(至少它不在我的知识领域)。但是,您可以限制一个请求,例如每天/每小时一次,并将结果存储在一个查找表中,然后您可以检查它,它取决于您的要求(它有多准确)以及数据必须有多新鲜)。但是,如果它回答了您的原始问题,请将其标记为已接受的答案,并随时发布一个可以回答您的新问题的新问题。
    • @user3466310 我想解决数据库速度的问题通常是数据库优化(使用适当的原子数据库和索引)而不是正在使用的函数本身。
    猜你喜欢
    • 2011-09-19
    • 2017-01-30
    • 1970-01-01
    • 1970-01-01
    • 2012-12-13
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多