SQL Server 2016 – Added information on TempDB Spill events – Showplan

Published Mar 23 2019 01:58 PM 169 Views
Microsoft
First published on MSDN on Oct 28, 2015
For those that have some experience analyzing query plans, you probably have come across spills to TempDB. These warnings can show up in Hash or Sort operations as a yellow exclamation mark. In fact, although both use TempDB, these are quite different in intent and also in implementation. For instance, a hashing operation that spills will be supported by a Workfile in TempDB, while a sort operation (amongst others) is supported by a Worktable.

A spill that occurs during a Sort operation is known as a Sort Warning . Sort warnings indicate that sort operations do not fit into memory. This does not include sort operations involving the creation of indexes, only sort operations within a query (such as an ORDER BY clause used in a SELECT statement).
If a query involving a sort operation generates a Sort Warnings event class with a spill level value of 2, the performance of the query can be affected because multiple passes over the data are required to sort the data. In the below example we see a spill level value of 1 , meaning that one pass over the data was enough to complete the sort. Still, this is using TempDB, and as such using I/O potentially with negative impact on the query performance.

To understand how impactful the spill is in this context, for a more complete analysis, it is important to know how much I/O we are talking about, and correlate that with the performance requirements for the query.
That is why in SQL Server 2016 we have enhanced the information about the spill. As seen below, the left image shows a Sort Warning up to SQL Server 2014, whereas the right image shows the SQL Server 2016 enhancement. There, we now can see how many threads spilled (this example shows a parallel execution), how many pages were involved in the spill, as well as the memory statistics for the operator, all in the Warnings section.





Another type of spill might occur during a Hash operation, which is known as a Hash Warning . These occur when a hash recursion or cessation of hashing (hash bailout) has occurred during a hashing operation.
Hash recursion occurs when the build input does not fit into available memory, resulting in the split of input into multiple partitions that are processed separately. If any of these partitions still do not fit into available memory, it is split into sub-partitions, which are also processed separately. This splitting process continues until each partition fits into available memory or until the maximum recursion level is reached.
Hash bailout occurs when a hashing operation reaches its maximum recursion level and shifts to an alternate plan to process the remaining partitioned data. These events can cause reduced performance in your server.

As seen below, the left image shows a Hash Warning up to SQL Server 2014, and the right image shows the SQL Server 2016 enhancement, with the same added information described for the Sort warning.



With this added information, when analyzing the plan, you now have a more complete picture of what a spill meant for your query performance.

Note : these changes where also backported to SQL Server 2012 SP3 .

Pedro Lopes ( @sqlpto ) - Program Manager
%3CLINGO-SUB%20id%3D%22lingo-sub-384521%22%20slang%3D%22en-US%22%3ESQL%20Server%202016%20%E2%80%93%20Added%20information%20on%20TempDB%20Spill%20events%20%E2%80%93%20Showplan%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-384521%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Oct%2028%2C%202015%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20For%20those%20that%20have%20some%20experience%20analyzing%20query%20plans%2C%20you%20probably%20have%20come%20across%20spills%20to%20TempDB.%20These%20warnings%20can%20show%20up%20in%20Hash%20or%20Sort%20operations%20as%20a%20yellow%20exclamation%20mark.%20In%20fact%2C%20although%20both%20use%20TempDB%2C%20these%20are%20quite%20different%20in%20intent%20and%20also%20in%20implementation.%20For%20instance%2C%20a%20hashing%20operation%20that%20spills%20will%20be%20supported%20by%20a%20Workfile%20in%20TempDB%2C%20while%20a%20sort%20operation%20(amongst%20others)%20is%20supported%20by%20a%20Worktable.%20%3CBR%20%2F%3E%3CBR%20%2F%3EA%20spill%20that%20occurs%20during%20a%20Sort%20operation%20is%20known%20as%20a%20%3CSTRONG%3E%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fms178041.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20Sort%20Warning%20%3C%2FA%3E%20%3C%2FSTRONG%3E%20.%20Sort%20warnings%20indicate%20that%20sort%20operations%20do%20not%20fit%20into%20memory.%20This%20does%20not%20include%20sort%20operations%20involving%20the%20creation%20of%20indexes%2C%20only%20sort%20operations%20within%20a%20query%20(such%20as%20an%20ORDER%20BY%20clause%20used%20in%20a%20SELECT%20statement).%20%3CBR%20%2F%3E%20If%20a%20query%20involving%20a%20sort%20operation%20generates%20a%20Sort%20Warnings%20event%20class%20with%20a%20spill%20level%20value%20of%202%2C%20the%20performance%20of%20the%20query%20can%20be%20affected%20because%20multiple%20passes%20over%20the%20data%20are%20required%20to%20sort%20the%20data.%20In%20the%20below%20example%20we%20see%20a%20%3CSTRONG%3E%20spill%20level%20value%20of%201%20%3C%2FSTRONG%3E%20%2C%20meaning%20that%20one%20pass%20over%20the%20data%20was%20enough%20to%20complete%20the%20sort.%20Still%2C%20this%20is%20using%20TempDB%2C%20and%20as%20such%20using%20I%2FO%20potentially%20with%20negative%20impact%20on%20the%20query%20performance.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20To%20understand%20how%20impactful%20the%20spill%20is%20in%20this%20context%2C%20for%20a%20more%20complete%20analysis%2C%20it%20is%20important%20to%20know%20how%20much%20I%2FO%20we%20are%20talking%20about%2C%20and%20correlate%20that%20with%20the%20performance%20requirements%20for%20the%20query.%20%3CBR%20%2F%3E%20That%20is%20why%20in%20SQL%20Server%202016%20we%20have%20enhanced%20the%20information%20about%20the%20spill.%20As%20seen%20below%2C%20the%20left%20image%20shows%20a%20Sort%20Warning%20up%20to%20SQL%20Server%202014%2C%20whereas%20the%20right%20image%20shows%20the%20SQL%20Server%202016%20enhancement.%20There%2C%20we%20now%20can%20see%20%3CSTRONG%3E%20how%20many%20threads%20spilled%20%3C%2FSTRONG%3E%20(this%20example%20shows%20a%20parallel%20execution)%2C%20%3CSTRONG%3E%20how%20many%20pages%20%3C%2FSTRONG%3E%20were%20involved%20in%20the%20spill%2C%20as%20well%20as%20the%20%3CSTRONG%3E%20memory%20statistics%20%3C%2FSTRONG%3E%20for%20the%20operator%2C%20all%20in%20the%20Warnings%20section.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F97895i7CD17359C31958AE%22%20%2F%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F97896i4E642F9AA7960E29%22%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3EAnother%20type%20of%20spill%20might%20occur%20during%20a%20Hash%20operation%2C%20which%20is%20known%20as%20a%20%3CSTRONG%3E%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fms190736.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20Hash%20Warning%20%3C%2FA%3E%20%3C%2FSTRONG%3E%20.%20These%20occur%20when%20a%20hash%20recursion%20or%20cessation%20of%20hashing%20(hash%20bailout)%20has%20occurred%20during%20a%20hashing%20operation.%20%3CBR%20%2F%3E%20%3CSTRONG%3EHash%20recursion%20%3C%2FSTRONG%3E%20occurs%20when%20the%20build%20input%20does%20not%20fit%20into%20available%20memory%2C%20resulting%20in%20the%20split%20of%20input%20into%20multiple%20partitions%20that%20are%20processed%20separately.%20If%20any%20of%20these%20partitions%20still%20do%20not%20fit%20into%20available%20memory%2C%20it%20is%20split%20into%20sub-partitions%2C%20which%20are%20also%20processed%20separately.%20This%20splitting%20process%20continues%20until%20each%20partition%20fits%20into%20available%20memory%20or%20until%20the%20maximum%20recursion%20level%20is%20reached.%20%3CBR%20%2F%3E%20%3CSTRONG%3EHash%20bailout%20%3C%2FSTRONG%3E%20occurs%20when%20a%20hashing%20operation%20reaches%20its%20maximum%20recursion%20level%20and%20shifts%20to%20an%20alternate%20plan%20to%20process%20the%20remaining%20partitioned%20data.%20These%20events%20can%20cause%20reduced%20performance%20in%20your%20server.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20As%20seen%20below%2C%20the%20left%20image%20shows%20a%20Hash%20Warning%20up%20to%20SQL%20Server%202014%2C%20and%20the%20right%20image%20shows%20the%20SQL%20Server%202016%20enhancement%2C%20with%20the%20same%20added%20information%20described%20for%20the%20Sort%20warning.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F97897i8E2FA5C332489173%22%20%2F%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F97898iC05DE3E5AFB5F9FA%22%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3EWith%20this%20added%20information%2C%20when%20analyzing%20the%20plan%2C%20you%20now%20have%20a%20more%20complete%20picture%20of%20what%20a%20spill%20meant%20for%20your%20query%20performance.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSTRONG%3ENote%20%3C%2FSTRONG%3E%20%3A%20these%20changes%20where%20also%20backported%20to%20%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Fkb%2F3107400%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20SQL%20Server%202012%20SP3%20%3C%2FA%3E%20.%20%3CBR%20%2F%3E%3CBR%20%2F%3EPedro%20Lopes%20(%20%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Fsqlpto%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20%40sqlpto%20%3C%2FA%3E%20)%20-%20Program%20Manager%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-384521%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Oct%2028%2C%202015%20For%20those%20that%20have%20some%20experience%20analyzing%20query%20plans%2C%20you%20probably%20have%20come%20across%20spills%20to%20TempDB.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-384521%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESQLServerTiger%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Mar 23 2019 01:58 PM
Updated by: