PromptsHub
Used by 5,000+ developers & creators
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

  1. 1Copy the slow-running SQL query into the prompt.
  2. 2Optionally provide the table schemas or index details.
  3. 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.