Sql server 不同参数值的不同执行计划
查询1运行速度快,并使用并行执行计划Sql server 不同参数值的不同执行计划,sql-server,sql-server-2008,Sql Server,Sql Server 2008,查询1运行速度快,并使用并行执行计划 SELECT c.[Date] FROM Table1 c left join Table2 bec on bec.Col1ID = c.Col1ID and bec.Active = 1 WHERE c.Active = 1 AND (c.Col2ID not in (3,4,5,6,7,8,9,10) or c.Col2ID is null) and (c.[Date] >= '06/12/2014 02:30:00.000 PM') SEL
SELECT c.[Date]
FROM Table1 c
left join Table2 bec on bec.Col1ID = c.Col1ID and bec.Active = 1
WHERE c.Active = 1
AND (c.Col2ID not in (3,4,5,6,7,8,9,10) or c.Col2ID is null)
and (c.[Date] >= '06/12/2014 02:30:00.000 PM')
SELECT c.[Date]
FROM Table1 c
left join Table2 bec on bec.Col1ID = c.Col1ID and bec.Active = 1
WHERE c.Active = 1
AND (c.Col2ID not in (3,4,5,6,7,8,9,10) or c.Col2ID is null)
and (c.[Date] >= '06/15/2014 02:30:00.000 PM')
查询2需要更长的时间,并使用正常(串行)执行计划
SELECT c.[Date]
FROM Table1 c
left join Table2 bec on bec.Col1ID = c.Col1ID and bec.Active = 1
WHERE c.Active = 1
AND (c.Col2ID not in (3,4,5,6,7,8,9,10) or c.Col2ID is null)
and (c.[Date] >= '06/12/2014 02:30:00.000 PM')
SELECT c.[Date]
FROM Table1 c
left join Table2 bec on bec.Col1ID = c.Col1ID and bec.Active = 1
WHERE c.Active = 1
AND (c.Col2ID not in (3,4,5,6,7,8,9,10) or c.Col2ID is null)
and (c.[Date] >= '06/15/2014 02:30:00.000 PM')
问题:
TABLE Table1(
Col1Id [int] IDENTITY(1,1) NOT NULL,
Col2Id [int] NULL,
Col3 [int] NOT NULL,
Col4 [int] NULL,
Active [bit] NOT NULL
[Date] [datetime] NOT NULL)
表1的索引
非群集开启(活动,日期)
表2的索引
包括[Active]上的非群集(列,列1ID)
聚集在(Col,Col1ID)
欢迎对此提供任何帮助。尝试将包含的列添加到Table1索引中,并在Table2上创建新索引。另外,确保统计数据是最新的
CREATE INDEX idx_Table1_Active_Date ON dbo.Table1 (Active, Date) INCLUDE (Col1Id, Col2Id);
CREATE INDEX idx_Table2_Col1ID_Active ON dbo.Table2 (Col1ID, Active);
你的桌子结构会很有帮助。还有你的索引。我刚刚更新了问题,Query1并行运行,Query2串行运行。如果需要静止表结构,请告诉我。是的。当然,帕特里克,我会在几分钟内更新这个问题。我不能马上做,因为我不能透露确切的表名和列名。公司政策:(。