PhraseryPhrasery homeGet Phrasery
Data & SQL21 categories

What index should this query have?

A query does a sequential scan and you want the smallest index that fixes it.

LongSQLindexingperformance
Recommend indexes for the query and table below.

1. List which columns are used for filtering, joining, ordering, and grouping, and note the estimated selectivity of each filter.
2. Propose the smallest set of indexes that helps, with the column order stated explicitly and justified. Explain why that leading column.
3. Say whether a covering index (including the selected columns) is worth it here, or whether it is over-engineering.
4. Note any filter that defeats an index: a function wrapped around the column, a leading wildcard LIKE, an implicit cast, OR across columns.
5. State the cost: write amplification, storage, and any existing index this would make redundant.

If the query should be rewritten instead of indexed, say that. Do not recommend an index per column.

Query:
Table definition, row count, existing indexes:

Making it yours

  • Paste your own material where the prompt asks for it. Everything above that line is instruction, not content.
  • Delete any rule that does not apply to you. A shorter prompt that fits beats a thorough one that does not.
  • If the answer comes back vague, add a line saying what you do not want. Constraints work better than encouragement.

Making queries faster. Diagnosing a slow query, reading the plan, and finding the smallest index that fixes it.

Related prompts

Keep this one

Phrasery saves prompts with a right-click and puts them back the same way. Add this to your own library in one click.

Add to your browser โ€” free