Code Room
Code reviewHard
Question
Review this SQL stored-procedure body (MySQL/InnoDB, REPEATABLE READ) that upserts a daily counter.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
START TRANSACTION; SELECT count FROM daily_counters WHERE day = CURDATE() AND metric = p_metric FOR UPDATE; -- if no row, insert itINSERT INTO daily_counters (day, metric, count) VALUES (CURDATE(), p_metric, 1); UPDATE daily_counters SET count = count + 1 WHERE day = CURDATE() AND metric = p_metric; COMMIT;Run or narrate your approach, then ask the coach.