在SQL Server(2008)中,我在两列上有一个FullText索引,称之为Table1.FirstNames
和Table2.LastNames
。在分析了一些查询后,我想出了以下结果:
SELECT *
FROM (Table1 LEFT JOIN Table2 ON Table1.SomeKey=Table2.SomeKey)
WHERE CONTAINS(FirstNames, 'Bob') OR CONTAINS(LastNames, 'Bob')
=> 31 197ms
SELECT *
FROM (Table1 LEFT JOIN Table2 ON Table1.SomeKey=Table2.SomeKey)
WHERE (FirstNames LIKE '%Bob%') OR CONTAINS(LastNames, 'Bob')
=> 1941ms
SELECT *
FROM (Table1 LEFT JOIN Table2 ON Table1.SomeKey=Table2.SomeKey)
WHERE CONTAINS(FirstNames, 'Bob') OR LastNames LIKE '%Bob%'
=> 3201ms
SELECT *
FROM (Table1 LEFT JOIN Table2 ON Table1.SomeKey=Table2.SomeKey)
WHERE CONTAINS(FirstNames, 'Bob')
=> 565ms
SELECT *
FROM (Table1 LEFT JOIN Table2 ON Table1.SomeKey=Table2.SomeKey)
WHERE FirstNames LIKE '%Bob%'
=> 670ms
SELECT *
FROM (Table1 LEFT JOIN Table2 ON Table1.SomeKey=Table2.SomeKey)
WHERE CONTAINS(LastNames, 'Bob')
=> 17MS
SELECT *
FROM (Table1 LEFT JOIN Table2 ON Table1.SomeKey=Table2.SomeKey)
WHERE LastNames LIKE '%Bob%'
=> 3ms的
即使重建FullText索引,此行为仍然存在。
对于特定语言的大型数据集,FullText通常比LIKE查询快得多,但为什么当我将两个FullText碰撞时,查询速度减慢一个数量级?
答案 0 :(得分:5)
更改为使用ContainsTable
有帮助吗?
它在这里Adding more OR searches with CONTAINS Brings Query to Crawl
同一个回答者(Joe Stefanelli)通过将FREETEXT
个谓词与OR
一起更改为FREETEXTTABLE
SQL Server full text query across multiple tables - why so slow? <,设法带来了类似的改进/ p>
答案 1 :(得分:0)
答案 2 :(得分:0)
我会看看每个人的执行计划。我猜你会从中学到很多东西。
Here is a decent link将向您展示如何显示执行计划以及解释它的一些提示。