Cut slow database query load times in half without rewriting your whole codebase
Beginner
10 min
English
Identify and fix performance bottlenecks in your SQL queries using AI-guided rewrites and indexing strategies.
Steps
- Open ChatGPT or Claude in your browser.
- Copy the prompt template below into the chat.
- Replace {sql_query} with the slow query you want to optimize.
- Fill {query_context} with details like table sizes, relationships, and what the query is supposed to return.
- Enter your database type (e.g., PostgreSQL, MySQL, SQL Server) in {db_engine}.
- Run the prompt and review the bottleneck analysis to understand why your query is slow.
- Copy the Optimized Query and test it in your local or staging database to ensure it returns the same results.
- Apply the Index Recommendations to your database migration script if the optimized query is successful.
Prompts to Use
You are an expert database administrator. Analyze the following SQL query and its execution context. Identify performance bottlenecks and suggest optimized versions.
Query: {sql_query}
Context: {query_context}
Database Engine: {db_engine}
Constraints:
- Do not change the query's output columns or row logic.
- Prefer standard SQL or engine-specific optimizations (e.g., indexes, query rewrite, partitioning).
- Explain the 'why' for each suggestion in plain language.
Output format:
1. Bottleneck Analysis
2. Optimized Query
3. Index Recommendations
4. Expected Impact
Tools Used
Some tool links may earn AiA a commission — never affecting rankings.