sql-server - 全文搜索 "Contains"比 "Like %"慢

标签 sql-server full-text-search contains sql-like

我在 SQL Server 2008 x64 上遇到全文索引问题。

我有三个表:

表 A 包含 90 000 行

TableB 有 12 000 000 行

TableC 有 22 000 000 行

我创建了具有自动填充功能的 FTS 目录。

当我查询TableA时:

Select * from TableA where Contains(field1, '"j*"')

我在不到 1 秒的时间内看到了 11000 条记录

但是当我使用相同的查询查询 TableB 或 TableC 时,我在 2 秒内看到 250 条记录。显然速度很慢。

对于相同的表,使用“like %”而不是“contains”的查询执行时间不到 1 秒。

这个问题是否是因为B表和C表太大而存在?表A查询成功。

也许这些表需要更多时间来建立索引? (但他们已经索引(填充)了 3 天)

一些细节:

对于表 B 和 C,我总是看到“总体状态 = 处理通知”(9)

属性“TableFulltextDocsProcessed”始终增加

(My SQL Server 有一个镜像实例。)

最佳答案

我不知道您的包含查询是否真的使用全文索引。我认为它必须进行全表扫描。据我了解,不同语言的全文索引索引词和词干。您点赞的查询

Select * from TableA where Contains(field1, '"j*"')

如果您使用

进行相同的搜索,则其中仅包含字符“j
Select field1 from TableA where Contains(field1, 'fish')

相比

Select field1 from TableA where field1 like '%fish%'

在这句话中,他们谈论了很多单词而不是字符。 SQL Server 2005 Full-Text Search: Internals and Enhancements

Full-text search allows fast and flexible indexing for keyword-based query of text data stored in a SQL Server database. Unlike the LIKE predicate, which only works on character patterns, full-text queries perform a linguistic search against this data, operating on words and phrases based on rules of a particular language.

所以我想知道如果短语“j”必须是全文使用的语言中的单词,那么 j* 是否有效。 看 CONTAINS (Transact-SQL)

Specifies a match of words or phrases beginning with the specified text. Enclose a prefix term in double quotation marks ("") and add an asterisk () before the ending quotation mark, so that all text starting with the simple term specified before the asterisk is matched. The clause should be specified this way: CONTAINS (column, '"text"'). The asterisk matches zero, one, or more characters (of the root word or words in the word or phrase)

执行计划是什么样的?

关于sql-server - 全文搜索 "Contains"比 "Like %"慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4077380/

相关文章:

sql - 使用 sql 使用 select 查询的结果更新现有列

sql-server - 您如何在数据库中表示继承?

elasticsearch - Elasticsearch中的复杂 bool 查询

Jquery 包含和不包含链接

sql iif语句连接表问题

sql - 删除...创建与更改

java - 全文搜索类似

php - 使用 utf8 的 MySQL 全文搜索(波斯语/阿拉伯语)

SQL 包含问题

jQuery If Contains 将 CSS 添加到多个值的类,同一个类