下面的查询需要更长的时间来执行,因为表有超过 50M 的记录,而且查询中的 OR 条件似乎不正确......谁能为我的查询提供优化版本。欣赏..!!
DECLARE @LastRunDate DATETIME
SELECT @LastRunDate=LastRunDateTime FROM [DataAudit].[t_DeltaSetting] da
WHERE da.[InterfaceName] = 'ATKInnovationTargetedCustomersToHANA'
SELECT distinct (initi.RecordID )
from WebData.t_Initiative initi
inner join WebData.t_InitiativeCustomer ic on initi.RecordID=ic.InitiativeId
inner join WebData.t_Tracker track on track.InitiativeId = initi.RecordID
inner join WebData.t_TrackerCustomer tc on tc.TrackerId=track.RecordID
where (initi.UpdatedDate > @LastRunDate)
or (ic.UpdatedDate > @LastRunDate)
or (track.UpdatedDate > @LastRunDate)
or (tc.UpdatedDate > @LastRunDate)