Learn Labs
Indexing & Query Planning

Self-test

Check your understanding

Self-test8 questions

—/8
  1. An index on (created_at, customer_id) made a customer's latest-orders query over 400 times slower than (customer_id, created_at). Explain using how a B-tree is sorted.

  2. Why did count(*) for a value matching 95% of rows still use the index, while sum(amount) for the same rows did a sequential scan?

  3. Why is a B-tree on a low-cardinality column like status much smaller in Postgres 13+ than you might expect?

  4. A covering index scan touched 19,252 pages right after an UPDATE and 161 after VACUUM. What changed?

  5. Why could an index on email not answer WHERE lower(email) = ..., and what fixed it?

  6. Five extra indexes made a bulk insert 8 times slower. How do you find indexes that are pure cost?

  7. In EXPLAIN ANALYZE output, which single signal most often reveals a bad plan?

  8. Design question

    Design the indexes for an orders table queried by: one customer's recent orders, all pending orders, and a nightly report by date range. Justify each, including what you would not index.