# postgres/foreign-key-indexes

> Checks that an index, a primary key, or a unique key leads with every foreign key column.

Checks that an index, a primary key, or a unique key leads with every foreign key column.

Part of the [`postgres`](/reference/configurations/postgres/) configuration, at the `recommended` [level](/start/concepts/#levels). It runs at the `commit` [stage](/start/concepts/#stage), once per scope. gspot runs this check itself.

## Why

Deleting a parent row scans the whole child table when the foreign key has no index.

## What to do

Create an index that starts with the foreign key column.

## Example

A foreign key on `orders.customer_id` without an index starting with that column reports a missing index. Add `CREATE INDEX orders_customer_id_idx ON orders (customer_id);` in the migration set.

## Turn it off

Turn it off for some files, with a reason:

```shell
gspot ignore postgres/foreign-key-indexes --paths "<glob>" --reason "<why>"
```
