PromptsHub
Used by 5,000+ developers & creators
Back to Developers
Developerssqldatabase-tuningperformance

Advanced SQL Query Performance Tuner

Analyzes slow SQL queries, explains performance bottlenecks, and provides optimized query rewrites along with index recommendations.

Use Case

Use this when database queries are slowing down application response times or consuming too much CPU.
AI Prompt
Act as an expert Database Administrator (DBA). Analyze the following slow SQL query and its execution plan (if available). Rewrite the query to optimize execution speed, reduce resource consumption, and prevent full table scans. Provide a clear list of recommended indexes and explain why specific bottlenecks (such as subqueries, joins, or filters) were addressed. Query: [insert query and optionally execution plan here]

How to Use

  1. 1Copy your slow SQL query and paste it into the placeholder.
  2. 2Include the execution plan if you have access to it for better results.
  3. 3Run the prompt and apply the optimized query and indexes to your database.

Example Output

The optimized query replaces the slow subquery in the WHERE clause with an inner join on the order stats table. We recommend adding a composite index on the orders table using the customer id and status columns to avoid a sequential scan. This change will allow the database engine to perform index seeks instead.