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

在执行一个查询语句时,发现 TOP(10) 和 TOP(100)所用时间差距很大。在对其调优时,发现 Sort Operator 消耗的时间高达95%,并抛出Warning:

1,为什么会出现warning?

To quote: Actual number of rows is 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 you can do in this situation is to make sure that 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 are essentially spills to disk.

SQL Server 抛出Warning的原因是Actual Number of Rows 和 Estimated Number of Rows 不一致,在SQL Server 在进行排序操作时,由于预先被授予的内存少于实际需要的内存时,导致SQL Server必须将中间结果集存储到tempdb中。如果修复这个warning,使全部数据都在内存中排序,就能提高查询语句的性能。

2,怎么使 Actual Number of Rows 和 Estimated Number of Rows 保持一致?

Why do 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 they‘re just big queries. (Remember, SQL Server uses memory for three things - caching raw data pages, caching execution plans, and workspace for queries. That workspace memory ends up being fairly small.)

How can I reduce spills?

By writing sargable T-SQL statements, having up-to-date statistics, putting enough memory in the server, building the right indexes, and interpreting the execution plans when things don‘t work out the way you expected. Check out Grant Fritchey‘s book SQL Server Query Performance Tuning for detailed explanations of all of those.

参考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

时间: 2024-08-12 04:24:37

Operator used tempdb to spill data during execution with spill level 1的相关文章

Spill data to tempdb

查看Execution Plan时,在Sort Operator上,发现一个Warning:Operator used tempdb to spill data during execution with spill level 1 以XML格式查看执行计划,发现一个SpillToTempDb的节点: <Warnings> <SpillToTempDb SpillLevel="1" /> </Warnings> Sort Warnings are r

监控 Data Flow Execution Performance

在每个Package执行时,SSIS Engine都会记录日志信息,Logging Level共有四个:无,基本,性能,详细.如果想监控Data Flow Execution的性能,可以将Logging Level设置为性能,这样就能收集每个数据流组件的“活动时间(以秒为单位)”. step1,设置日志记录级别为性能 2,查看package执行日志 3,点击“执行性能”,查看package的Execution Performance 查看数据路组件的各个组件的活动时间 如果数据流存在问题,那么可

operator new

document by C++: 系统的有三个声明: throwing (1) void* operator new (std::size_t size); nothrow (2) void* operator new (std::size_t size, const std::nothrow_t& nothrow_value) noexcept; placement (3) void* operator new (std::size_t size, void* ptr) noexcept; 定

Adaptively handling remote atomic execution based upon contention prediction

In one embodiment, a method includes receiving an instruction for decoding in a processor core and dynamically handling the instruction with one of multiple behaviors based on whether contention is predicted. If no contention is predicted, the instru

Method and apparatus for speculative execution of uncontended lock instructions

A method and apparatus for executing lock instructions speculatively in an out-of-order processor are disclosed. In one embodiment, a prediction is made whether a given lock instruction will actually be contended. If not, then the lock instruction ma

C++中的::operator new, ::operator delete

一般在使用new  和 delete的时候,做了两件事情,一是空间的配置( new 是分配,delete是回收),而是调用对象的析构函数 但是也有办法将这两个过程分开 那就是显式的调用::operator new, ::operator delete,它们只进行空间配置,并不调用对象的析构函数 具体的可以参看下面这个例子: // operator new[] example #include <iostream> // std::cout #include <new> // ::o

条款十七: 在operator=中检查给自己赋值的情况

在赋值运算符中要特别注意可能出现别名的情况,其理由基于两点.其中之一是效率.如果可以在赋值运算符函数体的首部检测到是给自己赋值,就可以立即返回,从而可以节省大量的工作,否则必须去实现整个赋值操作. 另一个更重要的原因是保证正确性.一个赋值运算符必须首先释放掉一个对象的资源(去掉旧值),然后根据新值分配新的资源.在自己给自己赋值的情况下,释放旧的资源将是灾难性的,因为在分配新的资源时会需要旧的资源. 看看下面string对象的赋值,赋值运算符没有对给自己赋值的情况进行检查: class strin

(2)kendo UI使用基础介绍与问题整理——Grid问题/demo、参数、data、filter等

项目中用到最多的组件是Grid,与它相关的问题也是最多的,下面我会成几个文章来说明. 这篇文章会介绍一些相关的常用参数. 一.demo及基本的参数说明 简单代码范例demo: <div id="grid"></div> <script> $(document).ready(function() { var data=[{ id:"1", cause:"包装破损", quantity:"5",

C++对bool operator &lt; (const p &amp;a)const的运算符重载详解

struct node { //定义一个结构体node(节点) int x; int y; int len; //node中有3个成员变量x,y,len bool operator <(const node &a)const {//重载<操作符.可以对两个node使用<操作符进行比较 return len<a.len; } }; 括号中的const表示参数a对象不会被修改,最后的const表明调用函数对象不会被修改! 重载运算符的介绍 C++中预定义的运算符的操作对象只能是