awesome-everything RU
↑ Back to the climb

Databases

Indexes: multiple-choice review

Crux Multiple-choice synthesis across the indexes unit — leading-column rule, partial and covering indexes, index-only scans and the Visibility Map, index-type selection, and production failure modes.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 13 min

Six questions that cut across the whole unit. None is a definition to recite — each mirrors a design call or an incident you weigh under real query load, where the wrong index costs storage, write throughput, or a 3am page.

Goal

Confirm you can connect B-tree anatomy, the leading-column rule, partial and covering indexes, index-only scans, index-type selection, and production failure modes — the synthesis the seven lessons built toward.

Quiz

A multi-tenant dashboard has an index on (workspace_id, status, created_at). A new analytics query runs WHERE status = 'pending' ORDER BY created_at DESC with no workspace_id filter, and it does a sequential scan. What is the fix that respects the unit's design discipline?

Quiz

A 100M-row tasks table is 80% status = 'done' (never queried by the dashboard). The dashboard only reads open and in_progress tasks. Which index strategy minimizes both size and write overhead?

Quiz

EXPLAIN (ANALYZE, BUFFERS) shows Index Only Scan with Heap Fetches: 12000 on an orders table, and the query is slow despite the right covering index. What is happening and what is the durable fix?

Quiz

A DELETE FROM posts WHERE id = 42 with ON DELETE CASCADE takes 7 minutes and holds locks the whole time, on a posts/comments schema. What is the root cause?

Quiz

orders.user_id is BIGINT with an index on orders(user_id). A query runs SELECT * FROM orders WHERE user_id = '42' (the literal is TEXT) and does a Seq Scan. Why, and what is the fix?

Quiz

A search feature runs WHERE title ILIKE '%invoice%' on a 50M-row table and takes 12 seconds. The query is keyword-style search over document text. What is the right index choice?

Recap

The unit’s through-line is one design loop: a composite is usable only from a leading prefix, so design it around the always-present filter; partial predicates cut a hot-subset index to a fraction of full size and skip writes for cold rows; INCLUDE plus a current Visibility Map make an index-only scan skip the heap; the index type must match the data shape (B-tree for ordered values, GIN for text and JSONB, HNSW for semantic); and the recurring failures — missing FK index, type coercion, stale stats, leading-wildcard ILIKE — all resolve back to matching the index to the exact question the query asks, verified with EXPLAIN (ANALYZE, BUFFERS).

Continue the climb ↑Indexes: free-recall review
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.