Back to Developers
DevelopersSQLdatabaseperformance
SQL Query Performance Optimizer
Analyzes slow-running SQL queries, suggests indexing strategies, and rewrites the query for optimal execution speed.
Use Case
Use when a database-driven application is bottlenecked by high latency or high CPU utilization on DB servers.
AI Prompt
Act as an expert Database Administrator (DBA). Analyze the following SQL query: [insert query here]. Identify performance bottlenecks, redundant subqueries, unnecessary joins, or full table scan triggers. Rewrite the query to optimize execution speed. Suggest appropriate database indexes (including composite indexes if needed) and explain the performance reasoning behind your optimization.
How to Use
- 1Copy the slow-running SQL query into the prompt.
- 2Optionally provide the table schemas or index details.
- 3Execute the prompt to get the optimized query and indexing recommendations.
Example Output
The main bottleneck in your query was the nested subquery in the SELECT clause, which forced a correlated execution for every row. I have rewritten this to use an INNER JOIN on a temporary CTE instead. To make this blazing fast, you should create a composite index on the orders table covering both the customer id and order date columns.
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