Code Room
Vibe codingMediumvc-g100
Subject Ai code reviewLevel Mid–Senior~15 minCommon in Databases & SQL interviewsIndustries Technology, Software development

Question

An AI assistant wrote this query to find recent failed logins by email domain. There's a btree index on `created_at` and one on `email`. The query is correct but does a full table scan on a 500M-row table and takes 40 seconds.

sql
SELECT user_id, email, created_atFROM login_attemptsWHERE DATE(created_at) = CURRENT_DATE  AND LOWER(email) LIKE '%@acme.com'  AND status = 'failed';

Why can't the existing indexes be used, and how do you make it fast?

What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it — tests, edge cases, reading critically — and how you’d re-prompt or decompose to get it right.

Describe your solution

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.