The execution plan is mentioned below. The SQL with this execution plan is running for over 16 minutes. SQL Server keeps on changing warning about what Indexes shall be built. Please advice.
Asked
Active
Viewed 377 times
-1
-
Please show us your table and (especially) index definitions. – Branko Dimitrijevic Feb 28 '20 at 11:06
-
Just from a cursory look at the plan I would for sure put an index on your #QM table. The estimated VS actual rows in those table spools is a huge red flag. – JMabee Feb 28 '20 at 11:36
1 Answers
0
- You can consider updating statistics for the [TM].[dbo].[Tb] table because there is a huge difference between the actual and estimated the number of rows in your execution plan.
SQL Server Statistics and how to perform Update Statistics in SQL
As a second phase, you can create a selective index for your #QM table. Indexing Temp Tables
In your Hash Match and Sort operator there is a warning "Operator used tempdb to spill data during execution with spill level 1, Operator used tempdb to spill data during execution with spill level 2"
Correct SQL Server TempDB Spills in Query Plans Caused by Outdated Statistics

Esat Erkec
- 1,575
- 7
- 13