Code Room
Code reviewMedium
Question
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.
Learn the concepts
CREATE TABLE events ( id BIGSERIAL PRIMARY KEY, tenant_id BIGINT NOT NULL, created TIMESTAMPTZ NOT NULL, level TEXT NOT NULL, payload JSONB);-- only the PK index exists SELECT id, level, createdFROM eventsWHERE tenant_id = $1 AND created >= now() - interval '24 hours' AND DATE(created) = CURRENT_DATEORDER BY created DESCLIMIT 100;Run or narrate your approach, then ask the coach.