Back to Developers
Developerssqldatabasequery-optimizationperformance
High-Performance Database Query Optimizer
Identifies bottlenecks, suggests indexes, and rewrites slow-running SQL queries for optimal performance.
Use Case
Use this when a query is running slow, causing database lockups, or when you want to optimize your application's database footprint before scaling.
AI Prompt
Act as an expert Database Administrator (DBA) and SQL Optimizer. Analyze the following SQL query and database schema details. Your task is to identify performance bottlenecks, explain why they occur (such as full table scans, bad joins, or missing indexes), and rewrite the query to make it run as fast as possible. Recommend any specific indexes (including composite indexes), partition strategies, or execution plan changes that would optimize this further. Query to optimize: [insert SQL query here] Schema details: [insert relevant database tables, column types, and existing indexes here]
How to Use
- 1Paste the slow-running SQL query into the prompt.
- 2Add any available details about the table schemas and current indexes.
- 3Run the optimizer and implement the rewritten query and recommended indexes in your database.
Example Output
The performance issue stems from a nested subquery and a missing index on the customer id foreign key. The optimized query replaces the subquery with an inner join, allowing the database query planner to execute the operations in parallel. Creating a composite index on the order date and status columns will eliminate the remaining sorting bottleneck.
Related Prompts
View AllPerformance 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
Algorithm Complexity and Big O Analyzer
Calculates the exact time and space complexity of an algorithm and offers optimized alternatives.
algorithmsbig-operformance
View Prompt