Partial and Expression Indexes
Index just the rows you care about with WHERE clauses, and index computed expressions (lower(email), date_trunc('day', ts)).
Partial Index: Index a Subset
A partial index covers only rows that match a WHERE clause at index creation. Smaller, faster, and great for the common-case query:
CREATE INDEX users_active_email_idx
ON users(email)
WHERE deleted_at IS NULL;When Partial Indexes Win
Use when:
- You always filter by the same predicate (e.g. soft-delete)
- One value dominates the column (e.g. 95% of rows have status='closed')
- You want a small, hot index in cache
All lessons in this course
- B-tree vs Hash vs GiST vs GIN Indexes
- Composite Indexes and Column Order
- Partial and Expression Indexes
- Index Maintenance and Bloat