Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 November SQL Server:Warning in Query Execution Plan, “Operator used tempdb to spill data during execution with spill level 2”

SQL Server:Warning in Query Execution Plan, “Operator used tempdb to spill data during execution with spill level 2”

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

Before a few days ago, When I was performing query optimization at that time I have seen one warning in the result of SQL Server Query Execution Plan like: “Operator used tempdb to spill data during execution with spill level 2”.
I performed RND on this and came to know very interesting reason this warning.

If you don’t know, please note that Database Statistics are playing main to prepare and generate the Query Execution Plan.

SQL Server Statistics contain different types of meta data information like total number records, indexes, access path and others.

This warning occurred because my database Statistics are not updated.
For example, my table has total 50000 records and Statistics contains only 5000 records information so the planner prepares the query execution plan according to 5000 records only.

While executing the query, If it finds more than 5000 records, It transfers other additional records first into TempDB and continue further process using TempDB. Because It calculated processing capacity only for 5000 records.

This process degrades the overall query performance and that’s why you can see a warning like: “Operator used tempdb to spill data during execution with spill level 2”.

The solution is:

Find Statistics data for tables and indexes and If Statistics data are not updated, update your Statistics data, so that Query Optimizer can prepare the best Query Execution Plan.

Check the Statistics for particular index:
If you find difference between Rows and Rows Sampled, Statistics is not updated.

1
DBCC SHOW_STATISTICS ("TableName", IndexName);

Update all Statistics for Database:

1
EXEC sp_updatestats;

Update Statistics for Table:

1
UPDATE STATISTICS TABLE_NAME;

Update Statistics for Index:

1
UPDATE STATISTICS TABLE_NAME INDEX_NAME;

Nov 18, 2016Anvesh Patel
MySQL: How to create a SQL Job or Event Scheduler for scheduling the Database TaskPostgreSQL: How to generate a DeadLock in a Database (ERROR: deadlock detected)
Comments: 2
  1. Sanket Makwana
    August 17, 2017 at 3:37 pm

    Awesome!

    i have updated statistics for table and warning is fixed.

    Thanks

    • Anvesh Patel
      Anvesh Patel
      August 17, 2017 at 7:07 pm

      Welcome!

Anvesh Patel
Anvesh Patel

Database Engineer

November 18, 2016 SQL ServerAnvesh Patel, AUTO_CREATE_STATISTICS, database, database research and development, dbrnd, Execution Plan, Query Optimizer, SQL Query, SQL Server, SQL Server Administrator, SQL Server Monitoring, SQL Server Performance Tunning, SQL Server Tips and Tricks, TempDB, TempDB Spill error, TSQL
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....