CodeBlanks Logo Icon CodeBlanks

Summary - Optimization

Improve a slow query with EXPLAIN.

Summary - Optimization

EXPLAIN shows the plan, indexes speed up, sargable uses indexes, JOIN solves N+1.

EXPLAIN SELECT * FROM products WHERE price > 100;

Summary optimization query.

All columns are selected from products. WHERE keeps only the rows where price > 100 holds.

Practice Summary - Optimization

Summary: EXPLAIN SELECT * FROM products WHERE price > 100.

Starter code

query.sql
-- summary optimization
EXPLAIN

Sample solution

query.sql
EXPLAIN SELECT * FROM products WHERE price > 100;

Expected output

Seq Scan on products

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What shows the query plan?

  • DESCRIBE
  • EXPLAIN Correct answer
  • SHOW
  • ANALYZE

Explanation: EXPLAIN shows the query plan.

2 Summary - Optimization: match the terms

Term Meaning
EXPLAIN plan
index speed
sargable indexed
N+1 JOIN

All lessons in Advanced