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.
Related prompts
Tech Lead's Guide to Code Migration Projects
Generates a structured migration plan covering assessment, strategy, phases, technical approach, risks, and timeline for moving codebases between technologies.
Code Refactoring Guide
Guides AI to analyze and refactor code using clean code principles, returning improved code with detailed explanations of each change.
Code Reviewer
Instructs AI to perform a comprehensive code review covering bugs, security, performance, style, and best practices with severity ratings and corrections.
Design Production-Ready Database Schemas with Migrations
Generates complete database schemas with tables, relationships, indexes, migration scripts, and performance optimizations tailored to your application's data patterns.
Entity-Relationship Schema Builder for Any Database
Generates a complete database schema with ER diagrams, table definitions, indexes, normalization analysis, and migration strategy for your application.
Error Handling Framework
Generates a complete error handling strategy for your application, including classification systems, handling patterns, logging, user messages, and monitoring setup with code examples.
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