One customer's orders through the link

One customer's orders through the link

The report shows the orders of a customer found by name. There is one customer with a dozen orders — and both tables are read whole. The join itself is not the problem — the problem is that there is no road to the customer's orders. Build it; an index on users.name is not needed in this task.

Speed this query up with an index
SELECT o.id, o.status, o.created_at
FROM orders o
JOIN users u ON u.id = o.user_id
WHERE u.name = 'Anna 100'
Requisito da solução
Apenas CREATE/ALTER/DROP — não é preciso um SELECT no final.

What counts as solved

You may only change the schema: indexes and ANALYZE. The query stays as the task wrote it — no need to send it back.

  • the plan has no Seq Scan on orders
  • the query reads at most 333 8 KB pages

Grading runs on a larger dataset than the samples show — the answer has to hold at scale.

PostgreSQLv16
Entre para enviar

O resultado da sua consulta aparecerá aqui

Focus radio
Paused · SomaFM · Fluid