Rebind and Rewind in Execution Plans

http://www.scarydba.com/2011/06/15/rebind-and-rewind-in-execution-plans/

Ever looked at an execution plan? If you answered no, you can’t possibly have ever tried to tune a query, or, you’re doing it wrong. For every one else, no doubt you’ve looked at the tool tips or the property sheets of an operator and you’ve seen the Rebind & Rewind properties and wondered what the heck they mean. Me too.

I learned as much as I could for the book on execution plans and I spent two pages describing it. Then, a little while ago, on the SQL Cruise, someone asked me to describe them and I was flummoxed. Specifically they said the explanation in the book was insufficiently clear, so I promised to put together a blog post on the topic, both to attempt to clarify my explanation and to reacquaint myself with the topic.

These properties reflect the number of times an operator was initialized, or started. It’s that easy for the initial definition. But it gets complicated quickly. Rebind & Rewind are only applicable when dealing with a loop join. They don’t apply to other situations, which is why they’re mostly zero when you see them. They are only applicable to the inner side of the loop.

Not only are Rebind and Rewind only involved with loop joins, but they only apply to certain operators: Nonclustered Index Spool, Remote Query, Row Count Spool, Sort, Table Spool, and Table-valued Function.

The difference between a rebind and rewind has to do with the values that are part of the loop join itself. As those values change, as different data is accessed in the outer part of the loop, you see rebinds. When those values aren’t changed then you’ll see a rewind. You’ll also see that the aggregation of these values is equal to the number of rows in the outer join.

Here’s an example query:

[sourcecode language=”sql”]SELECT  sod.SalesOrderDetailID FROM    Sales.SalesOrderDetail AS sod WHERE   LineTotal < (SELECT AVG(dos.LineTotal) FROM   Sales.SalesOrderDetail AS dos WHERE  dos.ModifiedDate < sod.ModifiedDate )[/sourcecode] It puts out an execution plan that’s pretty ugly, but at least it shoes a table spool in a loop join as you can see: 

If you look at the properties then we can see the values showing multiple rebinds and rewinds that total up to the number of rows in the outer part of the loop.

时间: 2024-10-29 10:46:21

Rebind and Rewind in Execution Plans的相关文章

【Oracle 优化器】自适应执行计划(Adaptive Execution Plans)

概述 自适应连接方法AJM AJM例 AJM的处理流程 自适应并行分配方法APDM APDM例 APDM的处理流程 关于分配方法 总结 参考 概述 我们知道在12c之前的版本,虽然有ACS.CFB等功能通过在SQL文执行时收集信息,来改善SQL文再次执行时的执行计划,但是在SQL文第一次执行时,只能根据统计信息做成的执行计划执行SQL,在执行过程中并不能改变. 如果统计信息不准确,访问的数据行数非常大并且选择的执行计划不是最优时,在SQL文第一次执行时可能会引起在灾难性的性能问题. 自适应执行计

《Pro SQL Server Internals, 2nd edition》的CHAPTER 3 Statistics中的Introduction to SQL Server Statistics、Statistics and Execution Plans、Statistics Maintenance(译)

<Pro SQL Server Internals> 作者: Dmitri Korotkevitch 出版社: Apress出版年: 2016-12-29页数: 804定价: USD 59.99装帧: PaperbackISBN: 9781484219638 统计 SQL Server查询优化器在为查询选择执行计划时使用基于成本的模型.它估计不同执行计划的成本,并选择成本最低的一个.但是,请记住,SQL Server并不搜索查询可用的最佳执行计划,因为评估所有可能的替代方案在CPU方面都是耗时

Oracle SQL explain/execution Plan

From http://blog.csdn.net/wujiandao/article/details/6621073 1. Four ways to get execution plan(anytime you want, for specified sql) ? Execute the SQL statement EXPLAIN PLAN, and then query the table where the output was written. ? Query a dynamic per

Execution Plan 执行计划介绍

后面的练习中需要下载 Demo 数据库, 有很多不同的版本, 可以根据个人需要下载.  下载地址 -http://msftdbprodsamples.codeplex.com/ 1. 什么是执行计划 查询优化器对输入的 T-SQL 查询语句通过"计算"而选择出效率最高的一种执行方案,这个执行方案就是执行计划. 执行计划可以告诉你这个查询将会被如何执行或者已经被如何执行过,可以通过执行计划看到 SQL 代码中那些效率比较低的地方. 查看执行计划的方式我们可以通过图形化的界面,或者文本,或

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 tim

Understanding how SQL Server executes a query

https://www.codeproject.com/Articles/630346/Understanding-how-SQL-Server-executes-a-query https://www.codeproject.com/Articles/732812/How-to-analyse-SQL-Server-performance This article will help you write better database code and will help you get st

sql是如何执行一个查询的!

引用自:http://rusanu.com/2013/08/01/understanding-how-sql-server-executes-a-query/ Understanding how SQL Server executes a query August 1st, 2013 If you are a developer writing applications that use SQL Server and you are wondering what exactly happens

Microsoft SQL Server Version List(SQL Server 版本)

原帖地址 What version of SQL Server do I have? This unofficial build chart lists all of the known Service Packs (SP), Cumulative Updates (CU), patches, hotfixes and other builds of MS SQL Server 2014, 2012, 2008 R2, 2008, 2005, 2000, 7.0, 6.5 and 6.0 tha

JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-004Table per class hierarchy(@Inheritance..SINGLE_TABLE)、@DiscriminatorColumn、@DiscriminatorValue、@DiscriminatorFormula)

一.结构 You can map an entire class hierarchy to a single table. This table includes columns for all properties of all classes in the hierarchy. The value of an extra type discriminator column or formula identifies the concrete subclass represented by a