Intermediate Topic 32 of 51 Databases
Query Execution Plans
Operator trees showing how a query will run.
How it works
An execution plan is the tree of physical operators that the database will run to answer a query, such as table scans, index seeks, nested loop, hash and merge joins, sorts and aggregates, with estimated or actual row counts and costs. EXPLAIN shows the plan, and EXPLAIN ANALYZE also runs it and reports actual times. Reading it from the innermost operators outward shows where time goes.
Step-by-step walkthrough
- The plan is a tree of operators.
- Rows flow from the leaves up to the root.
- A scan reads a table or index.
- The join combines two inputs.
- EXPLAIN shows this tree with estimated and actual costs.
Where it is used
Diagnosing slow queries, verifying that an index is used, comparing alternative rewrites and understanding join strategy use plans.
Common pitfall
Large gaps between estimated and actual rows point to stale statistics or correlated columns. A sequential scan is not always bad, since it can be best for small tables or when most rows match. Do not tune only by plan cost numbers; confirm with real timings and caching effects. Plans can change with data size and parameters.
Where it fits in the course
Query Execution Plans is topic 32 of 51 in Databases, rated Intermediate. It follows Query Optimization. The next topic is Window Functions.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Databases quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Databases quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Query Execution Plans?
Where do people use Query Execution Plans?
What is the most common mistake with Query Execution Plans?
What should I learn before this topic?
How can I practice it?
Is Query Execution Plans hard to learn?
How long does it take to learn Query Execution Plans?
Which topics are related to Query Execution Plans?
What should I study after Query Execution Plans?
Related topics
- Query Optimization (Databases)
- Window Functions (Databases)
- Stored Procedures and Triggers (Databases)
- Common Table Expressions (Databases)
- Out-of-Order Execution (Computer Architecture & Logic)
- Speculative Execution (Computer Architecture & Logic)
- Trusted Execution Environments (Security & Cryptography)