Design Indexes For A Query Workload
Recommends a minimal, high-impact index set for a set of queries with column order and covering rationale.
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.
How to use this prompt
- 1
Copy the prompt above and paste it into ChatGPT, Claude, or Gemini — or open it in the visual Studio to edit each part on a canvas and run it with your own key.
- 2
Replace any bracketed placeholders with your specifics. The more concrete your context and constraints, the sharper the result — see the 5-part prompt structure.
- 3
Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.
Techniques in this prompt
Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.
Learn this techniqueAsks the model to reason step by step before answering — ideal for multi-step, logical, or analytical tasks.
Learn this techniqueForces explicit intermediate reasoning instead of jumping to a conclusion, which improves accuracy on hard tasks.
Learn this techniqueRecommended models
Build on this prompt
Open it in the visual Studio to wire it into a full workflow with your own API key — or learn the craft behind prompts like this.
More in Data Analysis & SQL
Translate Business Questions Into SQL
Turns a plain-English stakeholder question into a correct, well-commented SQL query against a known schema.
Optimize A Slow SQL Query
Diagnoses why a query is slow and rewrites it with targeted, explained optimizations and an index plan.
Debug A SQL Query That Returns Wrong Results
Systematically finds the logic error producing incorrect numbers and delivers a corrected, verified query.
Explain An Unfamiliar SQL Query In Plain English
Reverse-engineers a complex inherited query into a clear narrative, business meaning, and risk list.