Optimize Database Query Performance
Use AI to analyze and optimize slow database queries. Get specific recommendations for indexing, query rewriting, and performance tuning.
Prompt Template
Variables to Customize
[DATABASE_TYPE] The database system being used
Example: PostgreSQL 14
[TABLE_SCHEMA] Description of relevant tables, columns, and relationships
Example: Users table (id, email, created_at), Orders table (id, user_id, total, order_date), OrderItems table (id, order_id, product_id, quantity)
[CURRENT_QUERY] The query that needs optimization
Example: SELECT u.email, COUNT(o.id) as order_count, SUM(o.total) as total_spent FROM users u LEFT JOIN orders o ON u.id = o.user_id WHERE o.order_date >= '2023-01-01' GROUP BY u.id, u.email HAVING COUNT(o.id) > 5 ORDER BY total_spent DESC;
[PERFORMANCE_ISSUES] Specific performance problems being experienced
Example: Query takes 45 seconds to execute, high CPU usage, frequent timeouts during peak hours
[DATA_VOLUME] Approximate size and scale of the data
Example: 2 million users, 15 million orders, 50 million order items
Example Output
Pro Tips for Best Results
- Always analyze the execution plan before and after optimization to verify improvements
- Test optimizations with production-like data volumes, as small datasets can be misleading
- Consider the trade-offs between read performance and write performance when adding indexes
- Use database-specific features like query hints or optimizer statistics when generic optimization isn't enough
- Monitor query performance over time as data distribution changes can affect optimal execution plans
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...
Write a Comprehensive Logging Configuration
You are an expert software engineer specializing in logging best practices. Create a comprehensive logging configuration...
Implement API Pagination System
I need to implement pagination for a REST API endpoint. Please provide a complete implementation with the following requ...
Refactor Legacy Code for Modern Standards
You are a senior software architect specializing in legacy code modernization. I need you to refactor the following [PRO...
Debug Network Request Failures
You are an expert network debugging specialist. I need help troubleshooting a network request failure. Please analyze th...
Create a Comprehensive Monitoring Dashboard
You are an expert DevOps engineer specializing in observability and monitoring systems. Create a comprehensive monitorin...