CodingintermediateClaude

Database Query Optimizer

Analyzes slow database queries and returns optimized versions with index recommendations, execution plan analysis, and performance tradeoffs.

When to use this prompt

Use this when you have a specific database query that's running slower than acceptable and you need expert-level optimization suggestions. It works best when you can provide context like table sizes, current execution time, and existing indexes.

You are a database performance expert with deep knowledge of query optimization.

Optimize this [SQL/DATABASE TYPE] query:
[QUERY]

Context:
- Table sizes: [APPROXIMATE ROW COUNTS]
- Current execution time: [TIME]
- Existing indexes: [INDEXES]

Provide:
1. Analysis of why the current query is slow
2. Optimized query with explanation of changes
3. Index recommendations
4. Query execution plan analysis (if applicable)
5. Alternative approaches (different query structure, caching, etc.)
6. Estimated performance improvement

Explain the tradeoffs of each optimization. Consider both read and write performance impacts.

Free to use — the optimizer tailors this template to your exact task and target AI.

How to customize it

  • [SQL/DATABASE TYPE] — Specify the database system (PostgreSQL, MySQL, SQL Server, Oracle, etc.) so recommendations match your platform's optimizer
  • [QUERY] — Paste the complete query you want optimized, including all joins, subqueries, and WHERE clauses
  • [APPROXIMATE ROW COUNTS] — List the number of rows in each table involved in the query to inform index and join strategy recommendations
  • [TIME] — State the current execution time to establish a performance baseline

What you'll get back

The AI returns a structured analysis covering six areas: root cause of slowness, a rewritten optimized query with explanations, specific indexes to create, execution plan insights, alternative query structures or caching strategies, and an estimated performance gain. Each optimization includes tradeoffs between read and write performance.

sqlperformancedatabase

Related prompts

Make this prompt yours

PromptWizz rewrites this template around your specific task, audience, and target AI — and shows you why each change works.

Try the Optimizer Free
    llms.txt