BeginnerCoder

Lesson 22 — Indexes & EXPLAIN (expert)

EXPLAIN QUERY PLAN: see what the database does

EXPLAIN QUERY PLAN before a SELECT shows how SQLite will run it instead of running it. "SCAN" means it reads every row; "SEARCH ... USING INDEX name" means it jumps straight to matches with that index. Checking the plan before and after adding an index proves the index is actually used.

EXPLAIN QUERY PLAN SELECT * FROM orders WHERE customer_id = 7

The last column of each plan row is a readable description.

Why it matters: "why is this page slow?" is usually answered by reading a query plan, not by guessing.

Want it another way?
Task

Write the CREATE INDEX on orders(customer_id) named idx_orders_customer. The second plan should then use it.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with Databases & SQL

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.