Extras · Lesson 3 of 22

Indexes - Speed Up Queries

An Index helps the database find data faster.

Like a book index - instead of reading every page, jump to the right spot.

Create an index:

CREATE INDEX idx_salary ON employees(salary);

Now queries filtering by salary are much faster!

Types:

  • B-tree - default, good for ranges
  • Hash - exact matches only
  • Composite - multiple columns

Trade-offs:

  • Faster reads
  • Slower writes (index must update)
  • Uses storage space

Index columns you frequently filter or join on.

Check your understanding

What is a trade-off of adding indexes?

Practice it on a real question

All SELECT & filtering questions

Practice on your iPhone

Query Dojo for iPhone has 85 interview questions, timed mock interviews and a tile builder, so you can write queries without a keyboard.

Get the app