Understanding the Query Optimizer
The query optimizer is an important part of the SQL Server database engine that generates the execution plan for a query based on the query operators, the schema, tables, hints, load on the SQL Server, the database statistics, and so on. The SQL Server database engine then decides and picks the optimal plan to execute the query. This optimal query execution plan might not be the best of all execution plans for the query but will be the best for the time when the query is getting executed. The query optimizer generation is a CPU-intensive operation and hence, Microsoft has designed it to store execution plans in a buffer called a plan cache. The optimizer first checks the existing query plans for the query and generates a plan if it doesn't find suitable plan in the plan cache; otherwise, it picks the best suitable plan from the plan cache.
The query optimizer uses parsing, binding, optimization, and execution steps to complete the query execution...