MySQLAbout 15 min

Report query scans the whole table

EXPLAIN reports access type ALL and rows in the hundreds of thousands, so every run of the report reads the whole table to count a small result, and that cost grows as the table does.

databasemysqlindexperformance

Failing now, on the candidate's machine
MySQL · candidate machine
candidate@lab:~$ docker exec metrics-db mysql -uroot -proot metrics -e "EXPLAIN SELECT COUNT(*) FROM events WHERE user_id=42 AND created_at > NOW() - INTERVAL 7 DAY"
candidate@lab:~$ time docker exec metrics-db mysql -uroot -proot metrics -e "SELECT COUNT(*) FROM events WHERE user_id=42 AND created_at > NOW() - INTERVAL 7 DAY"
candidate@lab:~$

The situation

You own an internal dashboard that runs a per-user activity report that reads events in MySQL (200,000 rows). The report runs often, and the DBA confirms a single query is hammering the database. Their ticket is in /home/easyenv/TICKET.md.

The rules a correct fix has to keep are in the brief the candidate reads when the test starts. They are not on this page, so nobody can read the answer ahead.

How to interview a database engineer

Most database engineer interviews ask questions about MySQL. This one asks for the work: a MySQL system with a real fault, a terminal and a clock. It is a challenge you can give a database engineer in a live interview or as a take-home.

The full database engineer interview

  1. 1

    Reproduces it first

    Sees the fault with their own eyes before touching anything.

  2. 2

    Reads before changing

    The logs, the config and the code around the fault.

  3. 3

    Fixes the cause

    Not the symptom, and not by turning a check off.

  4. 4

    Checks the rules

    Shows the fix keeps what the brief asks for, then finishes.

What the candidate gets

  • A real machine

    The broken MySQL system runs on its own Linux machine, built fresh for each candidate. Nothing to install: it opens in the browser.

  • A terminal and an editor

    The same tools they use at work, on the machine where the fault is.

  • About 15 minutes

    The suggested time for the task, from the challenge itself.

  • Checks, a replay and an AI review

    When they finish, the checks run on the machine. You read the result, the AI review and every command they typed.

Put it in your next interview.

Pick this challenge for a role, send the link, and watch the replay when they finish.