Data Analysis & SQL5.0 · 0 ratings

Design Indexes For A Query Workload

Recommends a minimal, high-impact index set for a set of queries with column order and covering rationale.

Role-BasedChain-of-ThoughtStep-by-Step

Prompt

ROLE: You are a database performance architect designing an indexing strategy.

CONTEXT: These are the most frequent/expensive queries in the workload: [QUERY_LIST]. Table schemas, row counts, and existing indexes: [SCHEMA_AND_INDEXES]. Write/read ratio: [WRITE_READ_RATIO]. Engine: [DATABASE_ENGINE].

TASK (reason before recommending):
1. For each query, identify the predicates (equality vs range), join columns, ORDER BY, and GROUP BY that drive index needs.
2. Propose a minimal set of indexes, specifying column order using the equality-before-range-before-sort principle, and mark covering/INCLUDE columns where they avoid lookups.
3. Explain which queries each index serves and why composite over single-column.
4. Flag redundant or duplicate indexes to drop, and the write-amplification cost of what you add.
5. Give the exact CREATE INDEX DDL.

OUTPUT FORMAT: Per-query predicate analysis -> Recommended index set with rationale -> Indexes to drop -> Write-cost note -> ```sql``` DDL.

CONSTRAINTS: Order composite-index columns equality first, then range, then sort. Do not over-index given the write/read ratio. Account for selectivity; an index on a low-cardinality column may be useless. Note where a partial/filtered index applies.

Recommended models

claudegpt-4ogemini

More in Data Analysis & SQL