Questions tagged [index-spool]

The index spool execution plan operator optimizes access to an intermediate result set by building a temporary nonclustered index in tempdb.

The Index Spool operator scans its input rows, placing a copy of each row in a hidden spool file (stored in the tempdb database and existing only for the lifetime of the query), and builds a nonclustered index on the data. This allows use of the seeking capability of indexes to output only those rows that satisfy a suitable predicate in a query plan.

An Index Spool is often an indication that optimal permanent indexes are not present in the database. The temporary index is only available to the query for which it is built, and will be fully rebuilt for every execution.

Index Spool can operate in Lazy or Eager mode. In lazy mode, rows are added to the index on demand. In eager mode, the operator consumes its entire input and builds the temporary index when the operator initializes. Unlike Table Spools, which only keep the most recently bound results for replay (rewind), Index Spool can rebind to previously-encountered rows as well as rewind.

The Index Spool's Seek properties define the column(s) on which the temporary nonclustered index is built. The Output List of the operator shows the key columns and any included columns. The output list may also be empty, in which case the spool is being used to check for the existence of a match only.

More details on the Index Spool can be found in this Simple Talk article.

8 questions
24
votes
1 answer

Why doesn't this query use an index spool?

I'm asking this question in order to better understand the optimizer's behavior and to understand the limits around index spools. Suppose that I put integers from 1 to 10000 into a heap: CREATE TABLE X_10000 (ID INT NOT NULL); truncate table…
Joe Obbish
  • 32,976
  • 4
  • 74
  • 153
16
votes
1 answer

Forcing an index spool

I know its something that should be avoided for performance reasons, but am trying to show a condition where it appears as a demo on how to make sure it does not appear. However, I end up with a missing index warning, yet the optimizer chooses not…
Akash
  • 1,032
  • 1
  • 9
  • 25
3
votes
1 answer

Speed Up Cross Apply Without Index Hint

I have a very small table with 12 rows in it that can be created with the following statement: CREATE TABLE dbo.SmallTable(ScoreMonth tinyint NOT NULL PRIMARY KEY, ScoreGoal float NOT NULL ); I…
1
vote
1 answer

Eager spool for update and delete on partitioned table

When I update or delete on partition table it shows eager spool in execution plan. Image for Update query execution plan showing eager spool:- I can’t understand why it is doing eager spool only when I am updating or deleting on partition table,…
0
votes
1 answer

Why do I get an index spool on a heap in scalar subquery?

I was reading this And I did the following: go create table fiirst ( col1 int, col2 int ); create table seecond( col1 int, col2 int ); with n1(c) as (select 0 union all select 0 ), n2(c) as ( select 0 from n1 as t1 cross join n1 as t2), n3(c) as (…
0
votes
1 answer

Plan changes to include Eager Spool causes the query to run slower

We have a reporting query which is erratic in terms of execution plan and run duration. It is either 5 seconds or as slow as 5 minutes. The query is a Select statement with no DML involved. One thing I noticed is the costly Eager Spool operator…
0
votes
1 answer

New Analyst SQL Optimization - Multiple Spools

Unfortunately my ability to Query has outgrown my knowledge of SQL Optimization, so i am hoping someone would help a young analyst by looking at this atrocious execution plan and provide some wisdom as to how i could speed it up. I've read a few…
-1
votes
1 answer

Index Update with Eager Spool and Sort operators in Execution Plan

After an UPDATE statement on a large table, the execution plan shows updates of indexes (all non-clustered) that include the updated columns. Before each index update, there is an Eager Spool operator followed by a very costly Sort. Overall, the…