Composite Indexes, WAL & Bloom Filters
Leftmost prefix rule, covering indexes, and skipping disk reads with Bloom filters.
In plain words
A phone book sorted by (Last Name, First Name) lets you quickly look up "Smith" or "Smith, Jane" - but NOT "all Janes" without reading every page. That’s the leftmost prefix rule!
Think of it like…
A Bloom filter is a bouncer who knows with 100% certainty who is NOT on the guest list, saving you from walking inside to check.
Theory & how it works
The Leftmost Prefix Rule & Covering Indexes
An index on (org_id, created_at) speeds up queries filtering by org_id alone OR (org_id, created_at), but does NOT help a query filtering only on created_at. Always put the highest-selectivity or equality column first.
A covering index (INCLUDE (status)) lets the database answer the entire query directly from the index without touching the main table heap at all.
Key points & practical guide
Summary checklist
- Composite index
(A, B)helpsAand(A, B), notBalone - Covering indexes avoid extra table heap lookups
- Bloom filters give zero false negatives, small false positives
When to use it
- Optimizing slow SQL queries and multi-tenant filters
Watch out for
- Adding separate indexes on every column - kills insert speed