473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Table Spool\ Lazy Spool

What causes the query optimizer to choose a table spool\lazy spool
action in the execution plan? The explanation of "optimize rewinds"
makes little sense because my query never comes back to that table.

I'm going to have to change the query but it would be helpful if I
knew what I should be trying to avoid.

David
Jul 20 '05 #1
1 20960
Your question regarding 'why' the optimizer chooses one type of plan over another isn't easily answered, unfortunately. The heuristics and complexities invovled in the query processor are so intricate that it's very hard to tell why it chose the plan it chose. The short answer is that it found its plan to be cheaper than the others it considered.

Spool operators are typically introduced into a query plan to 'cache' the results of complex query elements (large subqueries or remote scans, for instance), or to provide "Halloween protection" for update queries. The operator takes the rows produced by its children (those operators underneath it in the SET STATISTICS PROFILE tree) and stores them off into a table in TEMPDB so that it does not have to rescan or reevaluate the operators underneath it. In the case of a normal spool (usually referred to as an 'eager spool' (ES)), when the parent of the spool asks for a row, then the ES asks for ALL of the rows from the operators underneath it. In the case of a lazy spool (LS), the spool only stores the individual rows that are requested by its parent, not all of them. Many times, this is cheaper than retrieving all of the rows from its child. Unfortunately, while spools can provide a lot of performance benefit in preventing complex query elements from being updated over and over again, they can generate quite a lot of IO while they create the TEMPDB worktable.

Is the IO cost the reason that you are askign your question? Is this a normal SELECT or an UPDATE query? Perhaps some context would help. Can you post the query plan from SET STATISTICS PROFILE ON? Perhaps running your query through the index tuning wizard, or otherwise trying to optimize the index structure underlying your query would eliminate the need for the operator...

Thanks,
Ryan Stonecipher
SQL Server Storage Engine
"david_0" <do*****@yahoo.com> wrote in message news:58**************************@posting.google.c om...
What causes the query optimizer to choose a table spool\lazy spool
action in the execution plan? The explanation of "optimize rewinds"
makes little sense because my query never comes back to that table.

I'm going to have to change the query but it would be helpful if I
knew what I should be trying to avoid.

David
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Krzys! | last post by:
I'd like to create a table dynamicly. List of column in this table should be taken from select: "select distinct fiel from table " How to do it ? tnx in advance for help K.
0
by: Thomas R. Hummel | last post by:
Hello, I have a table which has a few million records. It has an IDENTITY column that serves as the primary key. In a part of our application here, a previous record may need to be copied as a...
7
by: Richard Lawrence | last post by:
Hi, Consider the following: #Content { margin:0px 210px 50px 200px; padding:10px; } If I use it with the following HTML:
0
by: Robert | last post by:
Greetings, In Google I am finding what the deffinition of a table spool operator is but not what it is doing to performance. The execution plan shows the output of a clustered Index scan (54...
1
by: orajit | last post by:
I Have created following PL/sql blok DECLARE vl_n_cnt NUMBER:=0; vl_max_date varchar2(100); CURSOR c1 IS SELECT CREATED_DTM,EVENT_DTM,ACCOUNT_NUM,EVENT_COST_MNY,EVENT_TYPE_ID ...
1
by: akaley | last post by:
HI.. iam using Spool ..for loading the data into file from select statement.. iam facing some problems...Please give me u r valuable suggestion.. This is the sample code used by me.. set...
2
by: apollock | last post by:
Our application is having an issue where a query in a stored procedure periodically gets a bad plan with a Lazy Spool Operator that changes the query execution time from 5ms to 900ms and kills our...
5
by: daves1 | last post by:
Hi, I am running an sql script in oracle to spool a csv file. I am using the following set up: Define name='JOE' spool names.txt set linesize 200 set pagesize 50000 set heading off set...
1
by: napstar | last post by:
I have a table in oracle 7.3 and I use SQLPLUS 8.0.6.0.0 to work with is DB.I would like to know how to spool the contents of a table to a txt file. i tried this spool c:\companies.txt SELECT ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.