Tutorial 7 of 8 · Databases and SQL · Databases in practice · Beginner
Indexes: why queries are fast or slow
See how the database finds rows, make a slow search fast with an index, and know when an index cannot help.
5 lessons, the last is a challenge · about 1 h · SQL
Before you start
You finished "Joining tables": you can write a WHERE test, sort with ORDER BY, count with COUNT(*) and join enrolments to students and courses.
You have met binary search (the "Binary search" tutorial): look at the middle of a sorted row and throw away the half that cannot hold the value. Lesson 2 explains it again in a few sentences if you skipped it.
1Say how the database finds rows when nothing helps it: it reads every row, so the work grows with the size of the table.
2Add an index that turns a scan into a search, and read the lines of a query plan: SCAN, SEARCH, the index used and the column it looks up.
3Say when an index cannot help (an ending, a function, arithmetic, OR, the second column alone) and what every index costs in space and in slower changes.