PromptsHub
Used by 5,000+ developers & creators
Back to Developers
Developerssqldatabaseperformance

SQL Query Analyzer and Performance Tuner

Diagnoses slow-running SQL queries and provides highly optimized query versions along with exact indexing recommendations.

Use Case

Use this prompt when database queries are slowing down application response times or consuming excessive server CPU and memory.
AI Prompt
Act as an expert Database Administrator (DBA). Analyze the following SQL query and its execution parameters. Rewrite the query to achieve maximum execution speed and minimum resource consumption. Explain the performance bottlenecks in the original query (such as subqueries, wildcard searches, or full table scans) and provide the exact CREATE INDEX statements required to optimize performance. SQL Query: [insert SQL query here] Optional Schema/Execution Plan Details: [insert database schema or EXPLAIN plan output here]

How to Use

  1. 1Paste the slow-performing SQL query.
  2. 2Provide database schema information, constraints, or EXPLAIN plan data if available.
  3. 3Implement the suggested index queries on your development database and verify the performance improvements.

Example Output

The original query suffered from performance degradation due to an implicit conversion in the WHERE clause and a correlated subquery. By rewriting the subquery into an inner join on the indexed user ID column and using explicit typecasting, execution speed is increased. Additionally, you should run the create index statement on the users table targeting both email and status columns.