Indexes and Performance
Table of Contents
Introduction: The Day My Blog Became Unusable
What Is an Index?
How PostgreSQL Finds Data Without an Index
B-Tree Indexes: The Default Workhorse
Naming Convention
Other Index Types in PostgreSQL
Hash Index
GIN Index (Generalised Inverted Index)
GiST Index (Generalised Search Tree)
BRIN Index (Block Range Index)
Index Strategies for Real Queries
Always Index Foreign Keys
Index Columns Used in WHERE Clauses
Index Columns Used in ORDER BY
EXPLAIN and EXPLAIN ANALYZE
Reading EXPLAIN Output
Term
Meaning
Partial Indexes: Index Only What You Need
Composite Indexes and Column Order
The "Equality First, Range Last" Rule
Index-Only Scans and Covering Indexes
The Cost of Indexes
When NOT to Add an Index
Query Optimisation Techniques
Avoid Functions on Indexed Columns in WHERE
Use LIMIT Aggressively
Avoid SELECT * in Production
SELECT * in ProductionUse Connection Pooling
Monitoring Index Usage
Find Unused Indexes (Index Bloat)
Find Slow Queries
Find Missing Indexes (Sequential Scans on Large Tables)
What I Learned About Performance
Next Steps
Last updated