Optimize SQL Query Performance
Get AI-powered SQL query optimization suggestions to improve performance, reduce execution time, and enhance database efficiency.
Prompt Template
Variables to Customize
[SQL_QUERY] The SQL query that needs optimization
Example: SELECT u.name, COUNT(o.id) as order_count, AVG(o.total) as avg_order FROM users u LEFT JOIN orders o ON u.id = o.user_id WHERE u.created_at > '2023-01-01' GROUP BY u.id, u.name ORDER BY order_count DESC
[DATABASE_TYPE] The database management system being used
Example: PostgreSQL 14
[TABLE_SCHEMAS] Relevant table structures and row counts
Example: users table (500K rows): id, name, email, created_at; orders table (2M rows): id, user_id, total, created_at
[PERFORMANCE_ISSUES] Specific performance problems being experienced
Example: Query takes 8-12 seconds to execute, causing timeout issues in the web application
[EXECUTION_FREQUENCY] How often this query runs
Example: Executed 200-300 times per hour during business hours
Example Output
Pro Tips for Best Results
- Always provide actual table schemas and row counts for more accurate optimization suggestions
- Include current execution plans (EXPLAIN ANALYZE) when possible for deeper analysis
- Specify your database version as optimization techniques vary between versions
- Mention any existing indexes to avoid redundant recommendations
- Test recommended optimizations on a copy of production data before implementing
Tags
Want 500+ Expert Prompts?
Get the Premium Prompt Pack — organized, tested, and ready to use.
Get it for $29Related Prompts You Might Like
Create Optimized Database Indexes
You are a senior database administrator with expertise in query optimization and index design. I need you to create opti...
Generate a Comprehensive Code Review Checklist
Act as a senior software engineer and create a comprehensive code review checklist for [PROGRAMMING_LANGUAGE] projects. ...
Debug Python Syntax Errors
You are an expert Python debugger helping beginners fix syntax errors. I need you to analyze the following Python code t...
Design Production-Ready GraphQL Schema
You are a senior GraphQL architect tasked with designing a comprehensive GraphQL schema for [PROJECT_TYPE]. Create a pro...
Handle API Error Responses
You are an expert API developer. Create comprehensive error handling code for API responses in [PROGRAMMING_LANGUAGE]. T...
Generate Regex Patterns for Text Matching
You are a regex expert helping to create precise regular expression patterns. I need a regex pattern for the following r...