Code Room
Code reviewHardcr-g649
Subject Sql index designLevel Senior–Staff~26 minCommon in Databases & SQL interviewsIndustries Software development

Question

Review this query and the index that was added to 'fix' it.

The `messages` table has 500M rows across ~100k channels.

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.

Talk through your review
Code to reviewsql
-- hot querySELECT id, bodyFROM messagesWHERE channel_id = 42  AND created_at >= now() - interval '7 days'ORDER BY created_at DESCLIMIT 50; -- the index someone addedCREATE INDEX idx_messages_created ON messages (created_at);
Run or narrate your approach, then ask the coach.