은 좀 기존 SQL (SP) 2 만 행 이상SQL Server 2005의 표 스풀 (게으른 스풀) - 성능
declare @FactorCollectionId int; select @FactorCollectionId = collectionID from dbo.collection where name = 'Factor'
declare @changeDate datetime; set @changeDate = getDate()
declare @changeTimeID int; set @changeTImeID = convert(int, convert(varchar(8), @changeDate, 112))
declare @MaxWindowID int; select @MaxWindowID = MAX(windowID) from dbo.window
select distinct @FactorCollectionId, ElementId, T.TimeID, @changeTimeId ChangeTimeID, 1 UserID, @MaxWindowID, 0 ChangeID
, null TransactionID, SystemSourceID, changeTypeID, 'R' OlapStatus, Comment, Net0 Delta0, Net0
, 1 CreatedBy, 1 UpdatedBy, @changeDate CreatedDate, @changeDate UpdatedDate, 1 CurrentRecord, MeasureTypeID
from dbo.aowCollectedFact FV
inner join dbo.timeView T on T.timeID >= FV.timeID
where FV.currentRecord = 1 --is current record
and T.CurrentHorizon <> 0 --Indicator that Time is part of current horizon
and FV.collectionID = @FactorCollectionId --factor collections only
and FV.timeID = (select MAX(timeID) --latest collected fact timeID for given collectionID and elementID
from aowCollectedFact FV2
where FV2.collectionId = @FactorCollectionId
and FV2.elementId = FV.elementID)
and (((T.ForecastLevel = 'Month') and (T.FirstDayInMonth = T.Date)) --Date is first of month for monthly customers, or
or
((T.ForecastLevel = 'Quarter')and (T.FirstDayInQuarter = T.Date))) --Date is first of quarter for quarterly customers
and not exists (select 1 --Record does not already exist in collected fact view
from aowCollectedFact FV3 -- for this factor collection, elementID, and timeID
where FV3.collectionId = @FactorCollectionId
and FV3.elementID = FV.elementId
and FV3.timeID = T.timeID)
이 SQL 프로세스를 가지고있다. 그 성능을 향상시켜야합니다. 실행 계획을 살펴보면 Table Spool (Lazy spool)
작업에 많은 시간이 소비된다는 것을 알 수 있습니다 (인덱스는 테이블에 존재하며 잘 작동합니다).
이 부분의 성능을 향상시키는 방법은 무엇입니까?
실제 성능, 시간 또는 디스크 IO를 알려주십시오. 또한 실행 계획 – Lamak
을 게시 할 수 있습니다. 또한 테이블에있는 인덱스와 사용중인 실제 실행 계획을 확인할 수 있습니까? – MatBailie
+1 좋은 질문입니다. 1k 이상 표시 – Malachi