Back to Developers
Developerssqldatabaseoptimization
Advanced SQL Query Optimizer
Analyzes and refactors complex SQL queries to reduce execution cost, leverage indexes, and improve database performance.
Use Case
Use this prompt when a database query is running slowly, causing timeouts, or consuming too much memory/CPU in production.
AI Prompt
Act as an expert Database Administrator and Performance Engineer. Analyze the following SQL query and schema information to optimize execution speed and resource consumption. Identify bottlenecks, suggest indexing strategies, and provide the fully optimized, refactored SQL query. Explain every optimization step you took and why it reduces execution cost. Here is the query: [insert SQL query] and schema: [insert DB Schema/Indexes].
How to Use
- 1Paste your slow-running SQL query into the designated placeholder.
- 2Include your table schemas, column types, and existing indexes for accurate results.
- 3Run the prompt to receive the optimized query and indexing suggestions.
Example Output
Optimized Query Analysis: The original query used a nested subquery that caused a full table scan. I refactored this into an INNER JOIN and utilized the composite index on user_id and created_at. This reduces the estimated query cost by 74 percent.
Related Prompts
View AllHigh-Performance Database Query Optimizer
Identifies bottlenecks, suggests indexes, and rewrites slow-running SQL queries for optimal performance.
sqldatabasequery-optimization
View Prompt
Performance Bottleneck & Profiler Analyst
Pinpoints execution hotspots, memory leaks, and inefficient algorithms in complex code snippets.
performanceoptimizationbig-o
View Prompt
High-Performance SQL Query Tuner
Analyzes sluggish database queries and returns optimized versions, detailing execution plan improvements.
sqldatabaseperformance
View Prompt