SQL Server Mastery

Execution Plans: Reading the Query Optimizer's mind

1 Views Updated 5/4/2026

Mastering Execution Plans

An Execution Plan is a visual map showing how SQL Server executed your query. It shows you exactly which indexes were used, how many rows were processed, and where the "cost" is. If you can't read an execution plan, you can't tune a database.

1. Index Seek vs Index Scan

  • Index Seek (GOOD): SQL Server used the index tree to jump directly to the data it needed. Fast and efficient.
  • Index Scan (BAD-ish): SQL Server had to read the *entire* index from beginning to end. Faster than a Table Scan but still means an index is being misused.
  • Table Scan (UGLY): No index was used. SQL Server read every single page in the table. Kill this immediately.

2. Key Look-ups & Spills

Look for the Key Lookup operator. It means your index isn't "Covering" the query. Also watch out for Sort/Hash Spills (yellow warning icons)—this means SQL Server ran out of RAM and had to use the slow TempDB to finish the task.

4. Interview Mastery

Q: "What is the difference between an Estimated and an Actual execution plan?"

Architect Answer: "The **Estimated Plan** is generated by the Optimizer based on statistics *before* any code runs. It is just a guess. The **Actual Plan** is generated *after* the query finishes and shows the real number of rows and memory used. You should always use the Actual Plan when debugging, as the Optimizer can be wrong if your statistics are out of date."

SQL Server Mastery
1. SQL Server Architecture & Basics
SQL Server Internals: How the Storage Engine works Relational Database Design & Normalization (1NF to 3NF) Data Types Mastery: Choosing the right type for performance
2. Advanced T-SQL Querying
Joins Deep Dive: Inner, Outer, Cross, and Self Joins Subqueries vs CTEs: Writing readable, high-performance code Window Functions: ROW_NUMBER, RANK, and LEAD/LAG Aggregations & Grouping Sets: Building complex reports Set Operators: UNION vs UNION ALL, INTERSECT, and EXCEPT
3. Indexing & Performance Tuning
Clustered vs Non-Clustered Indexes: The physical storage reality Covering Indexes & Included Columns: Reducing I/O costs Index Fragmentation: Why it happens and how to fix it Execution Plans: Reading the Query Optimizer's mind Statistics: Why 'Out of Date' stats kill performance SARGability: Writing queries that actually use indexes
4. Database Programmability
Stored Procedures: Security, Performance, and Best Practices User Defined Functions (UDF): Scalar vs Table-Valued Triggers: Auditing changes and the dangers of hidden logic Views & Indexed Views: Abstraction with performance Error Handling: TRY/CATCH and XACT_STATE()
5. Transactions & Concurrency
Transaction Isolation Levels: Read Uncommitted to Snapshot Locking & Blocking: Analyzing Deadlocks like a Pro Optimistic vs Pessimistic Concurrency
6. Administration & Security
SQL Server Security: Logins, Users, and Roles SQL Injection Prevention: Beyond simple parameterization Backup & Recovery Models: Full vs Simple vs Bulk-Logged Automating Maintenance: SQL Agent Jobs & Rebuilding Indexes
7. Modern SQL & Cloud
SQL Server & JSON: Storing and Querying semi-structured data Temporal Tables: Keeping track of data history automatically Introduction to Azure SQL: Database as a Service (PaaS) SQL Server Developer Interview: Junior to Senior Architect Level