Interview kitsBlog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2026 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Databases
Databaseshard

How do you read an EXPLAIN plan at a high level?

Tags
#explain#query-plan#performance
Back to categoryPractice quiz

Answer

Look at the biggest cost/time nodes first and the scan type (Seq Scan vs Index Scan) and row estimates. Then check joins/sorts and whether indexes are used as expected; fix with better queries, indexes, or stats.

Advanced answer

Deep dive

`EXPLAIN` shows the query plan: the steps the database *intends* to take. `EXPLAIN ANALYZE` runs the query and shows *actual* timing/rows.

How to read it (high level)

1) Focus on the nodes with the biggest time/cost. 2) Identify access paths:

  • sequential scan vs index scan
  • where filtering happens

3) Compare row estimates vs actual rows:

  • big mismatches often mean stale statistics or skewed data.

4) Understand join strategy (names vary by DB):

  • nested loop (good for small inputs / indexed lookups)
  • hash join (good for large, needs memory)
  • merge join (good for sorted inputs)

5) Watch for expensive sorts, temp spills, and repeated loops.

Typical fixes

  • Add/adjust indexes for filters and join keys.
  • Rewrite query to reduce rows earlier (filter before join, avoid `SELECT *`).
  • Refresh stats (e.g., `ANALYZE`) if estimates are wrong.

Common pitfalls

Related questions

Databases
Denormalization: when might you do it and what’s the trade‑off?
#database#denormalization#performance
Databases
What is a covering index (index‑only scan) and why can it be faster?
#database#indexes#covering-index
Databases
Why can the optimizer choose a bad query plan and how do statistics help?
#optimizer
  • Confusing planner “cost” with actual runtime.
  • Forcing indexes/hints without understanding selectivity.
  • Ignoring that a slow node inside a loop can be multiplied many times.
  • #statistics
    #cardinality
    Databases
    Index selectivity: what is it and why does it matter?
    #indexes#selectivity#performance
    Databases
    What is write amplification and why do many indexes make writes slower?
    #performance#indexes#write-amplification
    Databases
    What is a materialized view and when would you use it?
    #views#materialized-view#performance