×

sql · level 3 · unit 6 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

An lets the database jump straight to the rows it needs.

To find the parcels for one postcode, the database reads every row. Ten rows is nothing, ten million is slow. An index is like the index at the back of a book: a sorted list of values, each pointing to its rows.

CREATE INDEX idx_parcels_postcode ON parcels (postcode); builds one. To check it helps, put before a query: you get the plan instead of the rows.

means every row gets read. means the database jumps straight to the matches.

EXPLAIN QUERY PLAN
SELECT * FROM parcels WHERE postcode = 'LS1 4AB';

CREATE INDEX idx_parcels_postcode ON parcels (postcode);

EXPLAIN QUERY PLAN
SELECT * FROM parcels WHERE postcode = 'LS1 4AB';

The numbers in a plan change between SQLite versions, so read the words in the detail column.