SQL Server全文搜索性能在使用“或”时显着降低在where子句中 [英] SQL Server full-text search performance dramatically down when using "OR" in where clause

查看:163
本文介绍了SQL Server全文搜索性能在使用“或”时显着降低在where子句中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个表tab1,tab2。在这两个表的所有varchar列上创建全文索引。然后发出以下SQL:

  SELECT * 
FROM tab1 a
JOIN tab2 b on a.ID = b.ID
Where CONTAINS(a。*,@keystring)
或CONTAINS(b。*,@ keystring)

它非常缓慢(差不多30秒)。但是,如果我发出以下SQL:

  SELECT * 
FROM tab1 a
JOIN tab2 b on a。 ID = b.ID
WHERE CONTAINS(a。*,@keystring)

.. .or:

  SELECT * 
FROM tab1 a
在a.ID = b上加入tab2 b。 ID
WHERE CONTAINS(b。*,@ keystring)

性能相当不错小于秒)

如何解决这个问题?

解决方案

你有没有试过:

  SELECT * 
FROM tab1 a
JOIN tab2 b on a.ID = b .ID
WHERE CONTAINS(a。*,@keystring)
UNION
SELECT *
FROM tab1 a
JOIN tab2 b上a.ID = b.ID
WHERE CONTAINS(b。*,@ keystring)

或者如果不使用UNION,不要在乎keytring是否都是表的重复。



查看您的执行计划以查看差异, kes作为查询运行得更慢。


Suppose I have two tables tab1, tab2. Full text indexes created on all varchar columns on these two tables. Then issue following SQL:

SELECT *  
  FROM tab1 a 
  JOIN tab2 b on a.ID = b.ID
 WHERE CONTAINS(a.*, @keystring) 
    OR CONTAINS(b.*,@keystring)

It is pretty slowly(almost 30 seconds). But If I issue following SQL:

SELECT * 
  FROM tab1 a 
  JOIN tab2 b on a.ID = b.ID
 WHERE CONTAINS(a.*, @keystring) 

...or:

SELECT *  
  FROM tab1 a 
  JOIN tab2 b on a.ID = b.ID
 WHERE CONTAINS(b.*,@keystring)

The performance is pretty good(less than second)

How to resolve this problem?

解决方案

have you tried:

SELECT *  
  FROM tab1 a  
  JOIN tab2 b on a.ID = b.ID 
 WHERE CONTAINS(a.*, @keystring)  
UNION 
SELECT *   
  FROM tab1 a  
  JOIN tab2 b on a.ID = b.ID 
 WHERE CONTAINS(b.*,@keystring) 

Or use UNION all if you don't care if there are duplicates where the keystring is both tables.

Look at your execution plans to see the differnce but OR often makes as query run much more slowly.

这篇关于SQL Server全文搜索性能在使用“或”时显着降低在where子句中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆