Back to prompt library
Text · General-purpose LLMSQL Query Optimization MasterPW
CreatorPrompt2 Editorial DepartmentCurated by PromptWhisper
TextGeneral-purpose LLMDevelopment and engineering

SQL Query Optimization Master

Paste slow query SQL, AI analyzes execution plans, and provides optimized high-performance queries

233Views
Full promptReplace variables in braces, then use it directly

# 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 related tables] **Queries Needing Optimization**: [Paste SQL query] **Current Running Time**: [If You Know] **Data Size**: [Approximate Number of Rows] Please provide: 1. **Problem Diagnosis**: Analyze the performance bottleneck of the current query 2. **Execution Plan Analysis**: Estimate the execution plan and problem points 3. **Optimization Plan**: - Query rewriting (providing optimized SQL) - Index Suggestion (CREATE INDEX statement) - Table structure optimization suggestions (if needed) 4. **Optimization Principles**: Explain why each optimization works 5. **Notes**: Possible side effects of optimization ``` ## Usage Tips - Providing a complete table structure (including indexes) works even better - If you have EXPLAIN, provide the results as well - You can ask for optimization strategies for specific scenarios ## Applicable Models GPT-4、Claude 3.5、DeepSeek Coder

3/4/2026

How to use this prompt

  1. 1Copy the complete prompt above.
  2. 2Replace the topic, subject, or style variables.
  3. 3Save effective changes to build your own version.