skip to content
08, 12 chapters
indexes, from the outside
everything.indexes

indexes, from the outside

what an index is for, which queries it can help, and what it costs on every write.

start part 08part 08 of 18, 12 chapters
  1. 08.01what an index actually isa sorted copy of a few columns with an address back to each row. the back of a textbook, for tables.
  2. 08.02when postgres uses an indexslide the selectivity and watch the plan flip. random reads lose past a few percent.
  3. 08.03multicolumn indexescolumn order is everything. the leftmost prefix, equality first, range last.
  4. 08.04skip scanpostgres 18+postgres 18 can use an index on (a, b) for WHERE b = 5. how it hops, and when it can't.
  5. 08.05index-only scans and INCLUDEanswering from the index alone, the visibility map that makes it legal, and Heap Fetches: 0.
  6. 08.06partial and expression indexesindex only the rows you query, or lower(email) instead of email.
  7. 08.07indexes for ORDER BY and LIMITa sorted index means no sort node. the top 10 rows in three page reads.
  8. 08.08keyset paginationOFFSET 100000 reads 100,000 rows to throw them away. WHERE (a, b) > (x, y) doesn't.
  9. 08.09why isn't my index used?a function on the column, a type mismatch, a leading wildcard, an OR, too many matches. a checklist.
  10. 08.10what indexes costevery index is another write, more WAL and fewer HOT updates. finding the ones nobody uses.
  11. 08.11hash, GIN, GiST and BRIN, from the outsidewhich index type serves which operator, in one table you'll come back to.
  12. 08.12full-text and fuzzy searchtsvector, tsquery, ranking, pg_trgm for LIKE '%foo%', and the GIN index behind both.