B-trees: the workhorse of SQL.
Indexing Fundamentals: b-trees
shape data so reads and writes stay honest
Index size adds storage and write cost.
B-trees are balanced trees that keep keys sorted on disk and let the DB find a row in O(log N) page reads. Most relational indexes are B-trees; they accelerate equality and range queries.
Each index adds write cost (every insert/update touches the index).
Index-only scans are possible when the index covers all columns the query reads.
Selectivity matters: an index on (gender) is rarely useful.
Slow query: SELECT * FROM events WHERE user_id=$1 ORDER BY ts DESC LIMIT 50.