Interview replay

Full round replay — composite indexes

10 minintermediate212 yrs

Timed verbal replay with pass/fail criteria per follow-up.

How to run this

Answer out loud, timed. Do not read the entry first. Then compare against "The Answer" and "Interviewer's Next Move" and mark yourself.

The opener

Does an index on (a, b) help a query filtering only on b?

Budget: 45 seconds. Going long here is itself a fail signal.

Follow-ups

  1. 1. “Why not? Explain it physically.

    Testing: Reasoning from the sort order, not from a memorised rule.

    Scoring

    Pass: The index is sorted by a first and only by b within each a, so rows with a given b are scattered across every a block. There is no contiguous range to descend to.

    Fail: Repeats the rule with no mechanism behind it.

  2. 2. “Are (a, b) and (b, a) interchangeable?

    Testing: Do they treat order as a real decision?

    Scoring

    Pass: No — different indexes with different capabilities. One serves WHERE a = ? and an ordered read of b within an a; the other serves neither.

    Fail: Treats them as the same index written two ways.

  3. 3. “How do you choose the column order?

    Testing: The rule, in the right order.

    Scoring

    Pass: Equality columns first, then the range or ORDER BY column. Seeking stops at the first range column, so anything after it filters row by row rather than narrowing.

    Fail: Says most selective first, with nothing else.

  4. 4. “Isn't the most selective column supposed to go first?

    Testing: Whether they can rank the two rules.

    Scoring

    Pass: Usability first. A highly selective column that no query filters on is worthless in the leading position. Selectivity breaks ties between orderings that are all usable.

    Fail: Insists selectivity decides.

  5. 5. “Index on (a, b, c), query is WHERE a = ? AND b > ? AND c = ?. Is c used?

    Testing: The range-stops-seeking rule.

    Scoring

    Pass: Not for seeking. Once b is a range, entries in that range are ordered by b and no longer grouped by c, so c is checked row by row. Reorder to (a, c, b) and all three narrow the scan.

    Fail: Says all three are used because all three are in the index.

  6. 6. “The plan shows my index. Does that mean it is working?

    Testing: Seek versus scan.

    Scoring

    Pass: No. A full index scan also names the index. Compare rows read with rows returned — a large gap means the index was scanned rather than seeked.

    Fail: Takes the plan naming the index as confirmation.

  7. 7. “You have (customer_id) and (customer_id, status). Keep both?

    Testing: The redundancy rule and its boundary.

    Scoring

    Pass: No — the narrow one is a leading prefix of the wider one, so it is redundant. Drop it and save a write per insert. An index on (status) alone would not be redundant.

    Fail: Keeps both as insurance.

  8. 8. “A query is indexed and still slow. What would you try before adding an index?

    Testing: Widen versus add.

    Scoring

    Pass: Reorder, or widen an existing index to cover the selected columns. Both cost nothing extra per insert, because write cost is per index rather than per column.

    Fail: Adds another index first.

  9. 9. “What does a covering index cost?

    Testing: Can they name the downside?

    Scoring

    Pass: Bigger entries, so fewer per page, a taller index and more cache used. Good for a hot query with a short select list; wrong for SELECT *.

    Fail: Says it is free because it removes reads.

Score yourself

9/9 — you can design an index set and defend the ordering 7-8 — solid; the range-stops-seeking rule is where points go 5-6 — you know the leftmost prefix rule but not how to apply it; redo the Challenge 0-4 — run the Warm-up and enter the index from the wrong side

← Back to Does an index on (a, b) help a query filtering only on b?