Code RoomIneffective index for multi-column filter
HardPrep Room Coding #2273

Ineffective index for multi-column filter

Code reviewDatabases & SQLSenior–Staff~26 min

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.

0:00 of about 26 min
Mark a line and say what kind of problem it is.0 findings
1-- hot query
2SELECT id, body
3FROM messages
4WHERE channel_id = 42
5 AND created_at >= now() - interval '7 days'
6ORDER BY created_at DESC
7LIMIT 50;
8 
9-- the index someone added
10CREATE INDEX idx_messages_created ON messages (created_at);
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.