Database indexes and EXPLAIN: make slow SQL fast

10 steps · about 4 h · Intermediate

  1. Indexes and Performance · Learn SQL (interactive, learningsql.org, 25 min)

    A short first lesson on what an index is, with a before-and-after EXPLAIN QUERY PLAN comparison.

  2. 303 — Indexes and Query Performance (tutorial, devopspath.io, 30 min)

    You run commands against a SQLite database yourself and see SCAN change to SEARCH.

  3. SQL Indexes and EXPLAIN QUERY PLAN on 1M Rows (article, DEV Community, 20 min)

    It uses a 1M-row table to show real timing differences, then covers composite index column order and the patterns that make the database ignore an index.

  4. Anatomy of an SQL Index: What is an SQL Index (article, Use The Index, Luke (Markus Winand), 25 min)

    Once you've seen indexes work, learn the B-tree structure that explains why they behave that way.

  5. EXPLAIN QUERY PLAN (doc, SQLite.org, 20 min)

    The official guide to reading SQLite plan output, including joins, ORDER BY and subqueries.

  6. PostgreSQL: Documentation: 14.1. Using EXPLAIN (doc, PostgreSQL.org, 45 min)

    The standard walkthrough of costs, row estimates, scan types and EXPLAIN ANALYZE in a production-grade database.

  7. Indexing SQL range conditions less than, greater than and between (article, Use The Index, Luke (Markus Winand), 20 min)

    Teaches the rule of thumb to index for equality first and then for ranges, and how to spot access versus filter predicates in a plan.

  8. Index merge: using multiple indexes for one table access (article, Use The Index, Luke (Markus Winand), 15 min)

    Answers the common question of one index per column versus one multi-column index.

  9. Partial indexes: indexing selected rows (article, Use The Index, Luke (Markus Winand), 15 min)

    An advanced technique for keeping indexes small by indexing only the rows you search for.

  10. PostgreSQL: Documentation: EXPLAIN (doc, PostgreSQL.org, 25 min)

    Finish with the full reference for ANALYZE, BUFFERS and FORMAT, including how to run ANALYZE safely on writes inside a transaction.