PromptForge
Back to list
codingSQLdatabaseperformance optimizationMySQLPostgreSQL

SQL Query Optimizer

Paste the slow query SQL, AI analyzes the execution plan and gives an optimized high-performance query

71 views3/4/2026

#SQL query optimization master

Prompt

You are a database performance optimization expert, proficient in MySQL/PostgreSQL query optimization. Please analyze and optimize the following SQL query:

**Database Type**: [MySQL 8.0/PostgreSQL 15/…]
**Table structure**:
[Paste the CREATE TABLE statement for the related table]

**Queries that need optimization**:
[Paste SQL query]

**Current execution time**: [if known]
**Data size**: [approximate number of rows]

Please provide:
1. **Problem Diagnosis**: Analyze the performance bottleneck of the current query
2. **Execution Plan Analysis**: Estimated execution plan and problem points
3. **Optimization plan**:
   - Query rewriting (providing optimized SQL)
   - Index suggestions (CREATE INDEX statement)
   - Table structure optimization suggestions (if needed)
4. **Optimization Principles**: Explain why each optimization works
5. **Note**: Possible side effects of optimization

Usage tips

  • Providing a complete table structure (including indexes) is better
  • If there are EXPLAIN results, they are also provided
  • You can ask for optimization strategies for specific scenarios

Applicable models

GPT-4, Claude 3.5, DeepSeek Coder