Sql 通过在Table3MerchantDetailId上为此表添加索引,可能会得到一些改进。包含的列不能用于索引搜索,仅用于避免在其他索引列上搜索时访问聚集索引以返回列。您的索引中包含的列中也缺少[State],这将避免您的计划可能显示的聚集键查找。谢谢!我在
Sql 通过在Table3MerchantDetailId上为此表添加索引,可能会得到一些改进。包含的列不能用于索引搜索,仅用于避免在其他索引列上搜索时访问聚集索引以返回列。您的索引中包含的列中也缺少[State],这将避免您的计划可能显示的聚集键查找。谢谢!我在,sql,sql-server,performance,sql-server-2008,database-performance,Sql,Sql Server,Performance,Sql Server 2008,Database Performance,通过在Table3MerchantDetailId上为此表添加索引,可能会得到一些改进。包含的列不能用于索引搜索,仅用于避免在其他索引列上搜索时访问聚集索引以返回列。您的索引中包含的列中也缺少[State],这将避免您的计划可能显示的聚集键查找。谢谢!我在Table3MerchantDetailId上添加了一个索引,并在我包含的列中添加了状态,但它仍然显示图案填充内部联接的70%成本,现在索引查找更改为索引扫描,成本增加了15%。当WHERE子句中有带外部表条件的外部联接时,该联接作为常规内部联
通过在
Table3MerchantDetailId
上为此表添加索引,可能会得到一些改进。包含的列不能用于索引搜索,仅用于避免在其他索引列上搜索时访问聚集索引以返回列。您的索引中包含的列中也缺少[State]
,这将避免您的计划可能显示的聚集键查找。谢谢!我在Table3MerchantDetailId上添加了一个索引,并在我包含的列中添加了状态,但它仍然显示图案填充内部联接的70%成本,现在索引查找更改为索引扫描,成本增加了15%。当WHERE子句中有带外部表条件的外部联接时,该联接作为常规内部联接执行。移动到ON子句以作为真正的外部联接执行!(其中ar.RuleUsed=1…)感谢您的回复!我为ar.ruleused=1添加了on条件,但没有运气,执行计划显示了表4昂贵的图案填充内部联接。您可以发布执行计划中涉及表4
的分支的快照吗?根据查询优化人员选择的计划,您可以通过在table3merchantailid
上为此表添加索引来获得一些改进。包含的列不能用于索引搜索,仅用于避免在其他索引列上搜索时访问聚集索引以返回列。您的索引中包含的列中也缺少[State]
,这将避免您的计划可能显示的聚集键查找。谢谢!我在Table3MerchantDetailId上添加了一个索引,并在我包含的列中添加了状态,但它仍然显示图案填充内部联接的70%成本,现在索引查找更改为索引扫描,成本增加了15%。当WHERE子句中有带外部表条件的外部联接时,该联接作为常规内部联接执行。移动到ON子句以作为真正的外部联接执行!(其中ar.RuleUsed=1…)感谢您的回复!我为ar.ruleused=1添加了on条件,但没有运气,执行计划显示了表4昂贵的图案填充内部联接。您可以发布执行计划中涉及表4
的分支的快照吗?根据查询优化人员选择的计划,您可以通过在table3merchantailid
上为此表添加索引来获得一些改进。包含的列不能用于索引搜索,仅用于避免在其他索引列上搜索时访问聚集索引以返回列。您的索引中包含的列中也缺少[State]
,这将避免您的计划可能显示的聚集键查找。谢谢!我在Table3MerchantDetailId上添加了一个索引,并在我包含的列中添加了状态,但它仍然显示了图案填充内部连接70%的成本,现在索引搜索更改为索引扫描,成本增加了15%
Select Distinct * From(
select t.RuleId ,t.Table3Id,Null as RiskLeveltypeId,
(case when r.Count>=t.highlimit then 60 else
case when r.Count>=t.mediumlimit then 30 else
case when r.Count>=t.lowlimitthen 15 ELSE 0 end end end) as Score
,CreatedUser,GETDATE() as CreatedDate,CreatedUser as LastActivityUser,GETDATE() as LastActivityDate,
t.Table2Id,
t.Table1Id,
CardId,
249 as ClientId,
t.StmtDate
from ( (select Table2Id,Table3Date ,COUNT(Distinct Table4.[State]) As Count
from Table3Data
join Table4 on Table3Data.Table3MerchantDetailId=Table4.Table3MerchantDetailId
where Table3Data.ClientId=249
Group By Table2Id,Table3Date
having COUNT(Distinct Table4.[State])>1
)r
join
(Select ar.CreatedUser,ar.highlimit,ar.mediumlimit,ar.lowlimit, ar.RuleId,
t.Table2Id,ar.RiskLeveltypeId, t.Table3Id,t.Table3date,e.Table1Id,
ch.CardId,t.StmtDate
from Table2sData ch
join Table1 e on e.Table1Id=ch.Table1Id and e.clientid =ch.clientid
join Table3Data t on ch.Table2Id=t.Table2Id and t.ClientId=ch.Clientid and t.run is null
left join Table5 ar on e.AuditProfileId=ar.AuditProfileId
where ar.RuleUsed=1 and e.AuditProfileId= 205 and ch.CardId = 1
and ar.CardId = 1 and ar.RuleId=23 and t.StmtDate=CONVERT(varchar,'04/02/2015',112) and t.run is null and t.ClientId=249 ) t on r.Table2Id=t.Table2Id
and r.Table3Date=t.Table3Date)
)r where r.Score<>0
CREATE NONCLUSTERED INDEX IX_1 ON [dbo].table4
(
[ClientId] ASC
)
INCLUDE ( [State],
[table3MerchantDetailId]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
select Table2Id,Table3Date ,COUNT(Distinct Table4.[State]) As Count into #temp
from Table3Data
join Table4 on Table3Data.Table3MerchantDetailId=Table4.Table3MerchantDetailId
where Table3Data.ClientId=249
Group By Table2Id,Table3Date
having COUNT(Distinct Table4.[State])>1
select * from ( Select Distinct * From(
select t.RuleId ,t.Table3Id,Null as RiskLeveltypeId,
(case when r.Count>=t.highlimit then 60 else
case when r.Count>=t.mediumlimit then 30 else
case when r.Count>=t.lowlimit then 15 ELSE 0 end end end) as Score
,CreatedUser,GETDATE() as CreatedDate,CreatedUser as LastActivityUser,GETDATE() as LastActivityDate,
t.Table2Id,
t.Table1Id,
CardId,
249 as ClientId,
t.StmtDate
from (
select
ar.CreatedUser,
ar.highlimit,ar.mediumlimit,ar.lowlimit, ar.RuleId,
t.Table2Id,ar.RiskLeveltypeId, t.Table3Id,t.Table3date,e.Table1Id,
ch.CardId,t.StmtDate
from Table2sData ch
join Table1 e on e.Table1Id=ch.Table1Id and e.clientid =ch.clientid
join Table3Data t on ch.Table2Id=t.Table2Id and t.ClientId=ch.Clientid and t.run is null
left join Table5 ar on e.AuditProfileId=ar.AuditProfileId
where
ar.RuleUsed=1
and e.AuditProfileId= 205
and ch.CardId = 1
and ar.CardId = 1
and ar.RuleId=23
and t.StmtDate=CONVERT(varchar,'04/02/2015',112)
and t.ClientId=249
and exists (select 1 from #temp t1 where t1.Table2Id=t.Table2Id and t1.Table3Date=t.Table3Date) )t
join
(select [Count],Table2Id,Table3Date from #temp) r on t.Table2Id=r.Table2Id and t.Table3Date=r.Table3Date
)s where s.Score<>0
Drop table #temp