Skip to content
StackDecode
System Design
4. Database FundamentalsAnimated

Query Optimisation

Making queries run faster.

The idea

The optimiser chooses join order, indexes and algorithms using statistics. You help with indexes and better queries.

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. 1Measure slow queries
  2. 2Read the execution plan
  3. 3Add indexes or rewrite the query
  4. 4Re-test

Where it is used

Slow endpoints.

Watch out for

Optimising without looking at the plan.

Related