Paul White (@SQL_Kiwi) is an independent SQL Server technical consultant with 15 years experience, specializing in performance tuning the SQL Server Core Engine, and is well known for his expertise in execution plans, the query processor, and the query optimizer. Currently living in New Zealand, Paul writes the SQL Server internals blog Page Free Space at SQLblog.com.
Over the years, Paul has worked internationally on a number of high-volume critical systems where ultimate performance and reliability were the primary goals. A recently re-awarded SQL Server MVP, he contributes regularly to a range of web sites and forums, including Stack Exchange, SQL Server Central, SimpleTalk, and MSDN. Paul also speaks at a variety of user groups and community events such as SQL Saturdays and the annual SQL Pass Summit.
The Halloween Problem has a number of important consequences for SQL Server execution plans. In this final part of the series, we look at some of the tricks the optimizer uses to avoid adding an Eager Table Spool to every update query that might encounter the Halloween Problem.
The MERGE statement (introduced in SQL Server 2008) allows us to perform a mixture of INSERT, UPDATE, and DELETE operations using a single declarative statement. The Halloween Protection issues for MERGE are, logically enough, mostly a combination of the requirements for the individual operations performed, but there are some important differences and a couple of optimizations that apply only to MERGE.