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.

How to use this prompt

  1. 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. 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. 3

    Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.

Techniques in this prompt

Role-Based

Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.

Learn this technique
Chain-of-Thought

Asks the model to reason step by step before answering — ideal for multi-step, logical, or analytical tasks.

Learn this technique
Step-by-Step

Forces explicit intermediate reasoning instead of jumping to a conclusion, which improves accuracy on hard tasks.

Learn this technique

Recommended models

claudegpt-4ogemini

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