Understanding Query Plans

Whenever SQL Server executes a query, it first has to determine the best way to execute it. This decision involves deciding how and in which order to access and join the data, how and when to perform calculation and aggregations, and so on. This is done by a subsystem called the Query Optimizer. The Query Optimizer uses statistics about data distribution, the metadata relating to the database objects involved, index information, and other factors to calculate multiple possible query plans. For each of these plans, it estimates the cost based on statistics about the data and chooses the plan with the minimal cost for execution. Of course, SQL Server does not calculate all possible plans for every query because, for some ...

Get Microsoft® SQL Server™ 2005: Applied Techniques Step by Step now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.