# Add the index the slow-query log keeps asking for

An index the slow-query log has been recommending for months, added with the plan captured either side.

Category: Data layer and migrations
Source: https://letsship.ai/use-cases/add-the-missing-index
Published: 2026-08-25

## Goal

Add the index a slow query needs and record the plan before and after.

## Acceptance criteria

- The query plan is captured before and after
- The index is created without locking the table for an unacceptable time
- Write-path impact is considered and stated
- No redundant index is added that an existing one already covers

## What lands as proof

Two query plans showing the scan replaced by an index lookup, on production-like data volumes.

## Prompt

Copy this to an agent to open the ticket:

```text
Create a Linear issue in my team and assign it to the SHIP agent.

Title: Add an index for {query}

Description: Add the index a slow query needs and record the plan before and after.

Acceptance criteria:
- The query plan is captured before and after
- The index is created without locking the table for an unacceptable time
- Write-path impact is considered and stated
- No redundant index is added that an existing one already covers

Before you create the issue, read this repository's slow-query log and replace {query} with the worst repeated offender.
```

## Questions

### What does the agent actually change?

The ticket is scoped to one outcome: add the index a slow query needs and record the plan before and after. Work that serves that outcome is in scope, and anything outside it is left for a separate ticket, so the pull request stays reviewable.

### How do I know the work is done?

The pull request carries the evidence, not only the diff. Here that means query plan before and after, pasted into the pull request, so a reviewer can confirm the result without reproducing the work locally.

### How much oversight does this need?

The run stops once the plan is written. Somebody reads the approach and approves it before any code exists, which is the cheapest moment to redirect the work.
