Recipe
DB index strategy writer
Generate optimal composite indexes from query patterns. Feed it your WHERE clauses, JOIN conditions, and sort orders — get back the exact CREATE INDEX statements your schema needs.
Inputs
- Table schema (column names + types)
- Query workload: SELECT patterns with WHERE / JOIN / ORDER BY / GROUP BY
- Approximate row counts and cardinality estimates
Output
- Ranked list of composite index definitions
- Column order rationale per index
- Covering index suggestions where beneficial
Rules
- Equality filters first, range filters last
- High-selectivity columns before low-selectivity
- ORDER BY columns after WHERE columns
- Covering indexes include SELECT columns via INCLUDE
- Never exceed 5 columns per index without justification
This recipe pairs well with Slow Query Diagnostician — run that first to capture the queries, then feed them here.