我有一个cte,我使用嵌套循环连接从3个不同的表中获取数据。性能非常慢,一段时间后我得到超时错误。我检查了查询计划,发现问题出在嵌套循环连接上。
如何优化以下查询?任何帮助/建议将不胜感激。
with DCT as(
select distinct
p.PolicyReference as PolicyNumber,
Year(p.PolicyEffectiveDate) as PolicyYear,
reverse(substring(reverse(p.PolicyReference) , 1 , 2 )) as
PolicySequence,
p.PolicyEffectiveDate as InceptionDate,
p.PolicyExpirationDate as ExpirationDate,
p.AggregateLimitAmt_Orginal as AggregateLimit,
p.AttachmentPointAmt_Orginal as AttachmentPoint,
ch.DangerSignalDescription as DangerDescription,
ct.TransactiomAmountOriginal,
ch.PrimaryAllegation,
p.LOBCode as GLLOBCode,
p.BusinessUnit as GLLOBName,
p.ProducingOfficeCode as Office,
Null as CatCode,
p.PolicyBasisCode as PolicyTrigger,
Getdate() As ProcessDate,
From [vwPolicy] p
Inner Join [vwClaimHeader] ch ON p.PolicyReference = ch.PolicyReference
Inner Join [vwClaimTransactions] ct ON ch.ClaimSuffix = ct.ClaimSuffix)
select * from DCT;
我已附加查询计划执行,因为您可以看到嵌套循环占82%。我该如何克服这一点。这是一个非常直接的查询。