Cookbook recipe

Partial indexes for hot subsets of data

Applies to PostgreSQL 13–17 Last reviewed May 2026 Grounded in source
Estimated investigation4 min

Scenario

Most rows are "done" but you constantly query the few "pending" ones. A partial index covers only the hot subset — smaller, faster, cheaper to maintain. Diagnose it Confirm the predicate is selective, then index only…

Investigation Path

Most rows are “done” but you constantly query the few “pending” ones. A partial index covers only the hot subset — smaller, faster, cheaper to maintain.

Diagnose it

Confirm the predicate is selective, then index only that slice:

CREATE INDEX idx_jobs_pending
  ON jobs (created_at)
  WHERE status = 'pending';

Why it happens

A full index on a low-cardinality flag wastes space and write effort on rows you never query by that flag. A partial index stores only matching rows, so it is tiny and stays in cache.

This is a Pro lesson

Get every Learning Pathway and cookbook recipe — grounded in PostgreSQL source code, with diagnostics, fixes, and prevention for each topic.

Continue this lesson to learn:

  • How to fix it
  • Prevent it next time
  • Related & next steps
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Career Impact

This scenario builds production judgment and operational confidence under pressure.

Open Career Dashboard →

Keep going

Related & next steps

Was this helpful?

← All cookbook recipes