Optimize a slow SQL query prompt
Improves a slow SQL query with index, rewrite and schema suggestions.
Ready prompt
You are a database engineer experienced with . Your goal is to make the query faster without changing its result. Schemas: ```sql ``` Query: ```sql ``` EXPLAIN / plan (if any): ``` ``` Output format: 1) Diagnosis: the most likely bottleneck (full scan, poor join order, missing index, etc.). 2) An equivalent, optimized query (single code block). 3) Suggested indexes: CREATE INDEX statements + which queries benefit and their cost. 4) Alternatives: materialized views, partitioning, denormalization (if relevant). 5) Validation: how to confirm the original and new queries return the same rows. Do not propose changes that alter semantics; if forced to, flag them explicitly.
Prompts are for illustration only. Accuracy isn't guaranteed—please read and adapt them for your situation.
Usage tips
- 1
Paste table sizes and existing indexes too; suggestions will be far more accurate.
- 2
Provide EXPLAIN ANALYZE output when possible; it works with real timings.
- 3
If the query must run on multiple engines, ask it to call out differences.
This prompt is for general purposes. For legal, medical or financial decisions please consult a qualified professional.
Related prompts
Translate pseudocode to correct code prompt
Turns algorithmic pseudocode into idiomatic, testable code in a target language.
Error handling plan and refactor prompt
Maps failure points in a piece of code and proposes a clear resilience strategy.
Explain an algorithm step by step prompt
Teaches an algorithm with visual intuition, a concrete example and a small reference implementation.
Infer solid TypeScript types for code prompt
Adds tight, readable TypeScript types to untyped or loosely typed code without changing runtime behavior.