When UNION ALL Can Beat OR

Bert Wagner compares a couple methods for writing a query:

Suddenly those key-lookups become too expensive for SQL Server and the query optimizer thinks it’ll be faster to just scan the entire clustered index.

In general this makes sense; SQL Server tries to pick plans that are good enough in most scenarios, and in general I think it chooses wisely.

However, sometimes SQL Server doesn’t pick great plans. Sometimes the plans it picks are downright terrible.

If that particular topic is interesting, I’ve a blog post from a few years back on a similar vein.

Related Posts

Getting the Last Actual Plan

Grant Fritchey shows off an improvement in SQL Server 2019: I’ve always felt responsible for making such a big deal about the differences between estimated and actual plans. I implied in the first edition of the execution plans book (get the new, vastly improved, 3rd edition in digital form for free here, or you can pay for […]

Read More

Execution Plan Properties

Erik Darling reminds you to check out the properties of execution plan elements: I read a lot of posts about query plans, and I rarely see people bring up the properties tab. And I get it. The F4 button is right next to the F5 button. If you hit the wrong one, you might ruin […]

Read More

Categories

February 2018
MTWTFSS
« Jan Mar »
 1234
567891011
12131415161718
19202122232425
262728