I have a query that is taking over 2 hours to run. When I look at the execution plan for a major segment of it, 75% of the cost is on three instances of "Table Spool" (25% each). What is "Table Spool" and how do you address it? The execution plan lists this as
There are actually 2 queries involved. One loops through a series of dates and calls the second one. All joining fields have indexes in their corresponding tables:
-- Process all quarters
declare @lastQtrStart datetime
declare @currentQtrStart datetime
declare @currentQtrEnd datetime
set @currentQtrStart = '1/1/2008'
set @lastQtrStart = '1/1/2020'
while @currentQtrStart < @LastQtrStart
set @currentQtrEnd = dateadd(d , -1 , dateadd(MM , 3 , @currentQtrStart))
View Complete Post