
Lesson 08 · 12 min
Indexes and EXPLAIN
Why the same query takes 2 ms on one database and 2 seconds on another.
Without an index, the database reads the whole table (Seq Scan) and checks every row. A B-tree index keeps a column's values sorted with pointers to rows, so lookups by =, <, >, BETWEEN and sorting become fast (Index Scan). EXPLAIN ANALYZE runs the query and shows the plan: which method the database chose, how many rows, and how much time.
Sign in to continue
The rest of this lesson opens after sign up
The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.