Skip to content
StackDecode
System Design
4. Database FundamentalsAnimated

Query Execution Plans

The steps the database will take to run a query.

The idea

The plan shows scans, joins and index use, with cost estimates. EXPLAIN reveals it.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

App serversPrimary (writes)Replica 1 (read…Replica 2 (read…
  • client
  • gateway / proxy
  • service
  • cache
  • data store
  • queue / stream

Step one: add indexes and cache.

step:
1/4
at:
App servers
1/7

The green dot is a request moving through the system.

Step by step

  1. 1Run EXPLAIN
  2. 2Look for full scans
  3. 3Check estimated against actual rows
  4. 4Add or fix indexes

Where it is used

Diagnosing slow SQL.

Watch out for

Stale statistics make bad plans.

Related