Sql Server 2008性能问题组合CONTAINSTABLE和OR

时间:2013-07-25 14:02:54

标签: sql-server-2008

Table_X包含7000行 Table_Y包含1 000 000行

此请求在SQL Server2005上运行速度很快,但在SQL Server 2008上运行需要3分钟

SELECT [Extent1].[ID] AS [ID]   
FROM [dbo].[TableX] AS [Extent1]
INNER JOIN [dbo].[TableY] AS [Extent2] ON [Extent1].[ID] = [Extent2].[Fk_Id]
WHERE (
    (
        [Extent2].[Fk_Id] IN (
            (
                SELECT [KEY]
                FROM CONTAINSTABLE([TableX], (Description), N'"PMI_Log"') [CT]
                )
            )
        )
    OR (
        [Extent2].[id] IN (
            (
                SELECT [KEY]
                FROM CONTAINSTABLE([TableY], (Description), N'"PMI_Log"') [CT]
                )
            )
        )
    )

已经重建索引,统计数据和目录。

2个子查询(select..FROM ContainsTable ...)需要15ms

执行计划表示在表值函数[FulltextMatch]

中占用100%的时间

经过大量测试后,当我在FullText查询之间放置OR时,性能会下降。

有人可以帮忙吗?

THX,

这个问题显然是同一个问题:SQL Server 2008 Full-Text Search (FTS) extremely slow when more than one CONTAINSTABLE in query

1 个答案:

答案 0 :(得分:2)

这是SQL 2008/2008 R2的a known issue。它已在2008 SP1 CU92008 R2 CU4中修复。

作为一种变通方法,您可以将查询拆分为两个UNION结果。

SELECT 
   [Extent1].[ID] AS [ID]   
FROM 
   [dbo].[TableX] AS [Extent1]
   INNER JOIN [dbo].[TableY] AS [Extent2] 
   ON [Extent1].[ID] = [Extent2].[Fk_Id]
WHERE
   [Extent2].[Fk_Id] IN 
   (
      SELECT [KEY]
      FROM CONTAINSTABLE([TableX], (Description), N'"PMI_Log"') [CT]
   )

UNION

SELECT 
   [Extent1].[ID] AS [ID]   
FROM 
   [dbo].[TableX] AS [Extent1]
   INNER JOIN [dbo].[TableY] AS [Extent2] 
   ON [Extent1].[ID] = [Extent2].[Fk_Id]
WHERE
   [Extent2].[Fk_Id] IN 
   (
      SELECT [KEY]
      FROM CONTAINSTABLE([TableY], (Description), N'"PMI_Log"') [CT]
   )