22/30
Part 4 of 5 · Type trapsLearn
Each symptom points at a few bug classes
Run, compare, and name the class of each difference. One check usually tells the classes apart.
| Symptom | Points at | The check |
|---|---|---|
| A count or sum too high | counting rows, not things; a join that repeats rows | rows before and after each join; COUNT(*) against distinct keys |
| One side's sums too high, the other side's right | a fan-out | group the joined rows by the one side's key, keep counts above 1 |
| A row or group missing | an inner join; a WHERE on a LEFT JOIN's right side; a NULL comparison | keys on the left against rows in the output |
| No rows at all | NOT IN over a NULL; a condition that's never true | run the subquery alone; count NULLs in the column |
| 1 where 0 belongs | COUNT(*) over a LEFT JOIN's empty row | count a right-hand key instead |
| NULL where 0 belongs | SUM over no rows | wrap the sum in COALESCE |
| A rate of exactly 0 or 1 | integer division | look at the numerator and denominator alone, then cast an operand |
| Off at the ends of a range | BETWEEN on timestamps; an inclusive end; time zones | fixture rows late on the last day and just after it |