← Docs
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

  1. Equality filters first, range filters last
  2. High-selectivity columns before low-selectivity
  3. ORDER BY columns after WHERE columns
  4. Covering indexes include SELECT columns via INCLUDE
  5. 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.