Operator used tempdb to spill data during execution with spill level 1

Source: Internet
Author: User
Tags sql server query

When executing a query statement, it is found that the time difference between top (10) and top (100) is significant. When tuning it, it is found that the Sort Operator consumes up to 95% times and throws warning:

Operator used tempdb to spill data during execution with spill level 1

1, why does the warning appear?

To quote: Actual number of rows are greater then estimated one. SQL Server grants memory before execution, looking on estimated values. At run time it gets more rows then expected so sort spills in temp db. All of the can do in this situation was to make sure the estimated values are correct. Try to update statistics on involved tables. Remove predicates One-by-one to find one which leads to wrong estimates.

Spills to TempDB is essentially spills to disk.

The reason SQL Server throws warning is that actual number of rows and estimated number of rows are inconsistent when SQL Server is in a sort operation because the pre-granted memory is less than the actual required memory, causing s The QL server must store the intermediate result set in tempdb. If you fix this warning, all the data is sorted in memory, you can improve the performance of the query statement.

2, how do I keep the Actual number of rows and estimated number of rows consistent?

Why does queries spill to disk?

because SQL Server didn ' t grant them enough memory to complete their operations. Perhaps the execution plan underestimated the amount of memory required, or perhaps the box is under memory pressure, or T Hey ' re just big queries. (Remember, SQL Server uses memory for three things-caching raw data pages, caching execution plans, and workspace for Qu Eries. That workspace memory ends up being fairly small.)

how can I reduce spills?

By writing sargable T-SQL statements, have up-to-date statistics, putting enough memory in the server, building the Righ t indexes, and interpreting the execution plans when things Don's work out the the the-the-the-the-the-the-". Check out Grant Fritchey's book SQL Server Query performance Tuning for detailed explanations of all of THOSE.

Reference post:

Never Ignore a Sort Warning in SQL Server

SQL Server 2012:sort operator causing tempdb spill

Correct SQL Server TempDB spills in Query plans caused by outdated Statistics

Operator used tempdb to spill data during execution with spill level 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.