Customer deletion locks orders table
Review this SQL. Deleting a single customer takes 40 seconds and locks up the orders table.
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 24 min
Mark a line and say what kind of problem it is.0 findings
1CREATE TABLE orders (
2 id BIGSERIAL PRIMARY KEY,
3 customer_id BIGINT NOT NULL REFERENCES customers(id) ON DELETE CASCADE,
4 total NUMERIC,
5 created TIMESTAMPTZ
6);
7-- orders has 200M rows; the only index is the primary key.
8
9DELETE FROM customers WHERE id = $1;
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.