A SQL execution plan shows how a database will execute a query — the order of operations, joins,
filters, and scans. Understanding execution plans is essential for query tuning: identifying
bottlenecks, adding the right indexes, and choosing the best join strategy. This guide covers
EXPLAIN, query plans, indexes, join algorithms, statistics, and the 25 interview questions that
actually come up — with deep, descriptive theory aligned to the topic.
🎯 Key Takeaways
Execution plan shows how a query will run
EXPLAIN shows the plan without running
EXPLAIN ANALYZE runs and shows actual timing
Indexes speed up selective queries
Join algorithms affect performance
Statistics help the optimizer choose plans
25 Interview QuestionsBeginner to AdvancedEXPLAIN, Indexes, Joins, StatisticsUpdated Dec 3, 2026
KW
Kailas Warade
✓ Verified Author
Data Engineer · Oracle Certified · SQL & PL/SQL
Kailas works with SQL, PL/SQL, Python, and PySpark to build data pipelines.
He writes the SQL interview guides at Sankalan Data Tech, focused on
practical, real-world answers.
🏆 Oracle Certified💼 Data Engineer📝 SQL & PL/SQL Guides📍 Pune, India
A SQL execution plan shows how a database will execute a query — the order of operations,
joins, filters, and scans.
-- Execution plan flow
Query → Parse → Optimize → Execute Plan → Results
The core insight is that the same query can be executed many ways. The optimizer chooses
the best plan based on statistics, indexes, and query structure.
Understanding execution plans is essential for query tuning — identifying bottlenecks and
fixing them.
Execution plans are the starting point for all query optimization work.
EXPLAIN in Depth
EXPLAIN is a SQL command that shows the execution plan for a query without actually running
it.
-- EXPLAIN: estimated plan
EXPLAIN SELECT * FROM employees WHERE department_id = 5;
-- EXPLAIN ANALYZE: actual plan with timing
EXPLAIN ANALYZE SELECT * FROM employees WHERE department_id = 5;
EXPLAIN shows the estimated plan — what the optimizer thinks will happen. EXPLAIN ANALYZE
actually runs the query and shows the real timing and row counts.
EXPLAIN is safe to run anytime. EXPLAIN ANALYZE actually executes the query, so be careful
with expensive queries.
EXPLAIN is the first step in query tuning — it shows where the time goes.
Scans: Full Table vs Index
A full table scan reads every row in a table. An index scan uses an index to find only
relevant rows.
-- Full table scan: reads every row
SELECT * FROM employees; -- no filter, full scan
-- Index scan: uses index to find rows
SELECT * FROM employees WHERE department_id = 5;
-- If indexed on department_id, uses index scan
Full table scans are slow for large tables. Index scans are faster for selective queries.
A full table scan usually indicates a missing index or a query that cannot use an index.
Always check the execution plan to see which scan type is used.
Indexes in Depth
Indexes speed up queries by allowing the database to find rows without scanning the whole
table.
-- Single-column index
CREATE INDEX idx_dept ON employees(department_id);
-- Composite index (multiple columns)
CREATE INDEX idx_dept_name ON employees(department_id, last_name);
-- Covering index (includes all needed columns)
CREATE INDEX idx_covering ON employees(department_id, salary);
A single-column index works for queries filtering on that column. A composite index works
for queries filtering on multiple columns (in order).
A covering index includes all columns needed by a query, so the database does not need to
access the table itself.
Indexes speed up reads but slow down writes (INSERT/UPDATE/DELETE). Balance is key.
Join Algorithms in Depth
Join algorithms are the methods a database uses to combine rows from two tables.
Nested Loop Join. Compares every row in one table with every row in
another. Simple but slow for large tables. Good for small tables or when one side is
small.
Hash Join. Builds a hash table from one table and probes it with the
other. Fast for large tables with equality joins.
Merge Join. Sorts both tables and merges them. Efficient when both inputs
are already sorted.
The optimizer chooses the join algorithm based on table sizes and available indexes.
Statistics and the Optimizer
SQL statistics are metadata about data distribution that the query optimizer uses to choose
the best execution plan.
These are the execution plan and query tuning questions that come up most often in SQL and
data engineering interviews. Every answer stands on its own — read them in any order, or
work through them in sequence to build a complete understanding of execution plans,
EXPLAIN, indexes, join algorithms, statistics, and query tuning.
/
🔍
No matching questions found
Try a keyword like EXPLAIN, index, join, or statistics.
A SQL execution plan shows how a database will execute a query.
-- Execution plan flow
Query → Parse → Optimize → Execute Plan → Results
It shows the order of operations, joins, filters, and scans.
Understanding execution plans is essential for query tuning.
EXPLAIN is a SQL command that shows the execution plan for a query without actually
running it.
EXPLAIN SELECT * FROM employees WHERE department_id = 5;
EXPLAIN shows the estimated plan.
It is safe to run anytime.
EXPLAIN shows the estimated plan. EXPLAIN ANALYZE actually runs the query and shows
the actual plan with real timing.
EXPLAIN is safe. EXPLAIN ANALYZE actually executes.
A query plan is a tree of operations the database will perform to execute a query.
-- Query plan includes
Scans, joins, filters, sorts
It shows the order of operations.
It is the roadmap for execution.
A query profile shows how a query was actually executed.
-- Query profile shows
Time, data scanned, operators, bottlenecks
It shows real timing and row counts.
It is more accurate than a query plan.
A query plan shows how a query will be executed. A query profile shows how it was
actually executed.
Aspect
Query Plan
Query Profile
When
Before execution
After execution
Accuracy
Estimated
Actual
Use
Predict issues
Diagnose issues
Query plans predict. Query profiles diagnose.
A full table scan reads every row in a table.
-- Full table scan
SELECT * FROM employees; -- no filter
It is slow for large tables.
It usually indicates a missing index.
An index scan uses an index to find rows.
-- Index scan
SELECT * FROM employees WHERE department_id = 5;
-- If indexed, uses index scan
It is faster than a full table scan for selective queries.
It requires an index on the filter column.
A full table scan reads every row. An index scan uses an index to find only relevant
rows.
Aspect
Full Table Scan
Index Scan
Rows read
All rows
Only relevant rows
Speed
Slow for large tables
Fast for selective queries
Requires
No index
Index on filter column
Index scans are faster for selective queries.
A covering index includes all columns needed by a query.
-- Covering index
CREATE INDEX idx_covering ON employees(department_id, salary);
-- Query uses only index, no table access
SELECT department_id, salary FROM employees WHERE department_id = 5;
It improves performance by avoiding table access.
It is ideal for frequently-run queries.
A composite index is an index on multiple columns.
-- Composite index
CREATE INDEX idx_dept_name ON employees(department_id, last_name);
It is useful for queries filtering on multiple columns.
Column order matters — put the most selective column first.
A clustered index determines the physical order of data. A non-clustered index is a
separate structure that points to data.
Aspect
Clustered Index
Non-Clustered Index
Physical order
Determines it
Does not
Count per table
One
Many
Example
Primary key
Secondary index
Clustered index determines physical order. Non-clustered is a pointer structure.
A join algorithm is the method a database uses to combine rows from two tables.
Well-designed query tuning follows a few key principles.
Use EXPLAIN — always start with the execution plan.
Add indexes — on filter and join columns.
Avoid SELECT * — scan only needed columns.
Update statistics — keep them fresh.
Avoid correlated subqueries — rewrite as JOINs when possible.
Use appropriate joins — let the optimizer choose, or hint if needed.
-- Well-tuned query
SELECT e.name, d.dept_name
FROM employees e
JOIN departments d ON e.dept_id = d.id
WHERE e.department_id = 5;
-- With index on department_id
These principles produce queries that are fast and efficient.
Mistakes I Keep Seeing in Interviews
These come up repeatedly. None of them are exotic, and every one of them is easy to avoid
once you know it is coming.
Mistake one: not using EXPLAIN. Always start with the execution plan.
Mistake two: confusing EXPLAIN with EXPLAIN ANALYZE. One estimates, one
executes.
Mistake three: ignoring full table scans. They are slow and usually
indicate a missing index.
Mistake four: not understanding join algorithms. They affect performance
significantly.
Mistake five: not updating statistics. Outdated statistics lead to bad
plans.
Mistake six: overusing query hints. Let the optimizer choose unless it
makes a bad choice.
Follow-Up Questions Interviewers Ask
Getting the first answer right is only half the interview. What usually decides the
outcome is what happens next. Here is what to prepare for on the execution plan topic.
After “What is an execution plan?” — expect
“What is EXPLAIN?”
“What is EXPLAIN ANALYZE?”
“What is the difference?”
“How do you read a plan?”
After “Indexes” — expect
“What is a covering index?”
“What is a composite index?”
“What is the difference from clustered?”
“When would you use one?”
After “Join algorithms” — expect
“What is a nested loop join?”
“What is a hash join?”
“What is a merge join?”
“When would you use each?”
After “Statistics” — expect
“What is cardinality estimation?”
“What is a cost-based optimizer?”
“What is a query hint?”
“How do you update statistics?”
For every question above, prepare a second-level answer. The candidates who pass are not
the ones who memorized the first answer — they are the ones who kept going for another
thirty seconds and said something useful about why it matters.
Quick Quiz
Five questions to check whether the topics above have landed.
1. What does EXPLAIN do?
2. What is the difference between EXPLAIN and EXPLAIN ANALYZE?
3. What does a full table scan indicate?
4. Which join algorithm is best for large tables with equality joins?