Code RoomDashboard query times out
MediumPrep Room Coding #1836

Dashboard query times out

Code reviewDatabases & SQLMid–Senior~25 min

Review this SQL query + schema. The `events` table has 800M rows and this dashboard query times out.

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 25 min
Mark a line and say what kind of problem it is.0 findings
1CREATE TABLE events (
2 id BIGSERIAL PRIMARY KEY,
3 tenant_id BIGINT NOT NULL,
4 created TIMESTAMPTZ NOT NULL,
5 level TEXT NOT NULL,
6 payload JSONB
7);
8-- only the PK index exists
9 
10SELECT id, level, created
11FROM events
12WHERE tenant_id = $1
13 AND created >= now() - interval '24 hours'
14 AND DATE(created) = CURRENT_DATE
15ORDER BY created DESC
16LIMIT 100;
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.