Measuring B-Tree Index Bloat on High-Churn Status Columns
Job queues stored in relational tables often index a status column where rows transition from pending to completed and stay completed forever. Even with PostgreSQL B-tree deduplication, indexing millions of historical completed rows wastes buffer cache.
Replacing the full index with a partial index scoped to WHERE status IN ('pending', 'running') routinely shrinks the index from gigabytes to a few hundred kilobytes, keeping hot pages pinned in shared_buffers.
Combine partial indexing with HOT (Heap-Only Tuple) updates by ensuring frequently mutated columns are excluded from unrelated secondary indexes.
CREATE INDEX CONCURRENTLY idx_jobs_active
ON work_queue (scheduled_at, priority)
WHERE status IN ('pending', 'running');