Counter upsert hangs intermittently
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.
0:00 of about 32 min
Mark a line and say what kind of problem it is.0 findings
1START TRANSACTION;
2
3SELECT count FROM daily_counters
4 WHERE day = CURDATE() AND metric = p_metric
5 FOR UPDATE;
6
7-- if no row, insert it
8INSERT INTO daily_counters (day, metric, count)
9 VALUES (CURDATE(), p_metric, 1);
10
11UPDATE daily_counters SET count = count + 1
12 WHERE day = CURDATE() AND metric = p_metric;
13
14COMMIT;
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.