Exercise 2: The N+1 Query Pattern in Ticket 2 — Possible Solution ==================================================================== WHAT "N+1 QUERY PATTERN" MEANS HERE ------------------------------ Per this chapter, the error log showed "hundreds of individual database query log lines per single export request" and the root cause was described as new code that "queries the database once per row instead of once for the whole export." An N+1 pattern means: instead of one efficient query that retrieves everything needed at once, the code issues one additional separate query for every individual row/item being processed - so an export covering hundreds of rows triggers hundreds of separate database round-trips instead of one. WHY COMPARING TO YESTERDAY'S DEPLOYMENT WAS THE KEY STEP ------------------------------ Per this chapter, "the access log... confirms export requests genuinely spiked from ~1s to 20s+, starting right after yesterday's 2pm deployment," and the actual explanation only emerged when "yesterday's deployment notes show a code change to the export feature - comparing the before/after query counts confirms" the new per-row querying behavior. Without connecting the timing of the slowdown to the timing of a specific code change, the hundreds of query log lines alone would show THAT queries were happening excessively, but not WHY that pattern suddenly started - the deployment record is what supplied the missing "why." WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly defines the N+1 pattern using this chapter's own description (one query per row instead of one query total), and correctly explains why matching the slowdown's timing to a specific deployment was necessary to actually identify the cause, not just observe the symptom.