Speed up lookups on a rare status
In orders 95% of rows have status paid, and only 5% are pending. The hot monitoring query is «give me every pending order from the last hour».
A plain status index covers every row in the table and ends up too fat — pending drowns in paid. The fix is a partial index that physically holds only pending rows: about 20× smaller and faster to scan. Build a partial index named orders_pending_idx on the id column of orders, restricted by the condition status = 'pending'.
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in