Make a slow query fast without changing its answer

A dashboard query takes 40 seconds. Read its plan, work out why, and make it fast. The only hard constraint is that the result set must be byte-identical to the original, including for rows involving NULLs. A fix that is fast and slightly wrong is worth less than no fix at all, which is why equivalence carries as much weight here as speed.

Part of the SQL & Data Analysis course~120 minutesEvidence: a write-upWe mark it against a checklist you can read first
01 · What counts as done

What you have to hand in

  • The plan is included, before and after.
  • The cause is named and supported by the plan, not guessed.
  • Timings are shown for both versions on comparable data.
  • Equivalence is demonstrated across the full result set, not spot-checked.
  • The change is the smallest one that fixes the cause, and any heavier alternative you rejected is named.
02 · How it will be marked

The checklist, published before you start

We score your work against each line below, and every score has to quote the part of your work it is based on. You read all of it first, so you can argue with any score on the specifics.
  • The cause is correctly identified30% of the grade

    The submission names why the query was slow, with evidence from the plan.

    1. AbsentGuesses at a cause with no evidence.
    2. DevelopingNames a plausible cause but does not support it from the plan.
    3. Competent— this is the pass markNames the real cause and cites the plan.
    4. StrongNames the cause, cites the plan, and rules out a competing explanation.
  • The query is measurably faster30% of the grade

    Before and after timings on comparable data.

    1. AbsentNo measurement, or no improvement.
    2. DevelopingImproved, but measured only once or on unrepresentative data.
    3. Competent— this is the pass markClear improvement, measured on representative data.
    4. StrongClear improvement with the measurement method described well enough to repeat.
  • The result is unchanged30% of the grade

    The faster query returns exactly the same rows as the original.

    1. AbsentThe result changed and this was not noticed.
    2. DevelopingResult is the same on a spot check only.
    3. Competent— this is the pass markEquivalence demonstrated on the full result set.
    4. StrongEquivalence demonstrated, including for NULL and edge-case rows.
  • The fix is proportionate10% of the grade

    The change is the smallest one that solves the problem, without unnecessary new indexes or denormalisation.

    1. AbsentAdds indexes or tables with no justification.
    2. DevelopingThe fix works but does more than needed.
    3. Competent— this is the pass markA minimal, targeted change.
    4. StrongMinimal, with the rejected heavier alternatives named and dismissed.
03 · What this proves

The skills a pass would prove

Pass, and these skills count as proven, with this piece of work attached as the evidence.

This brief is part of the SQL & Data Analysis course

Starting it starts the course: every skill above, in the order they depend on each other, with this brief at the end as the thing you hand in — marked against the checklist you have just read and nothing else.

About three minutes to set up: what you want to do with SQL & Data Analysis, where you are starting from, and how many hours a week you actually have. The subject we already have from this page.Start the SQL & Data Analysis course
See the whole SQL & Data Analysis course, or every graded brief we run.

One cookie, so we can see which subjects people finish and where the site loses them — plus a replay of where you click. Nothing you type is recorded, and once you’re signed in the words on screen are blanked out too. No advertising, nothing sold. The detail.