Essentially this procedure (particularly the final Select statement) was showing up in plan cache metrics as a top reader, million+ page reads per run. User traced issue to the Optimizer and the table variables do not maintain statistics and therefore often are estimated to 1 row returned, resulting in a bad query plan that does a looped table scan of Sysjobhistory.
As a workaround user added "option (recompile)" to the statement in question. However upgrading Spotlight will overwrite this change.
WORKAROUND:
Add "option (recompile)" to last Select statement in this scrip.
STATUS:
Product enhancement SOSSE-4201 logged for future release of Spotlight on SQL Server Enterprise.
© ALL RIGHTS RESERVED. Terms of Use Privacy Cookie Preference Center