Index a foreign key column Postgres never indexed for you
orders.customer_id references customers.id — the foreign key is already in place and enforced. What surprises a lot of people: Postgres does not automatically create an index on the referencing column of a foreign key (only on the referenced side, because a primary key already implies one). Every lookup of "this customer's orders" is currently a full scan of orders.
Create an index on orders.customer_id.
Schema
| id | INT |
| name | TEXT |
| id | INT |
| customer_id | INT |
| amount | NUMERIC |
Example input
Stuck? Ask the coach for a nudge that won't give the answer away, or reveal the reference solution and a short walkthrough of why it works.