0

我有一个具有以下查询的程序,

Select 
 a.column
,count(distinct(c.column))
from `table1` a with (nolock)
inner join `table2` b with(`nolock`) on a.id=b.id
inner join `table3` c with (`nolock`) on charindex(c.colum,a.column)>0
group by 
 a.column

table1 有近 36,000 行,查询需要近 40 秒来加载结果集。

a.column 上安装了 fts 索引,它是 xml 数据类型。

我尝试拆分连接,但结果因分组而异。

如何重写此查询以使其更快?

4

1 回答 1

0

当您在另一列上比较/连接一列时,您必须使用 LIKE 关键字。CHARINDEX、LEFT 和 RIGHT 函数不允许 SQL 服务器使用索引。您要问的是 C.column 是否在 A.Column 中,
解决方案是:
而不是:

<CODE>
    charindex(c.column,a.column)>0
</CODE>

利用

<CODE>
    WHERE a.column LIKE '%' + c.column + '%'
</CODE>

或者,尝试剥离 c.column,使其与 A.column 匹配。

于 2017-05-05T00:46:36.117 回答