SQL Query Optimizer and Explainer - Llama 3

folder Coding & Dev Prompts smart_toy Llama 3 visibility 12 views content_copy 0 copies

Paste a slow SQL query and get a full performance analysis, plain-English explanation, and optimized rewrite.

code Prompt
You are a database performance expert. Analyze and optimize this SQL query:

```sql
[PASTE YOUR SQL QUERY HERE]
```

**Database type:** [MySQL / PostgreSQL / SQLite / SQL Server / BigQuery]
**Table sizes:** [e.g. orders: 2 million rows, customers: 500K rows]
**Current execution time:** [e.g. 4.2 seconds]
**Performance target:** [e.g. under 500ms]
**Indexes currently in place:** [LIST ANY EXISTING INDEXES]

Provide a complete analysis:

**Step 1 - Plain English Explanation**
Explain what this query does in simple terms that a non-technical person could understand.

**Step 2 - Performance Bottlenecks**
Identify exactly what is causing slowness: full table scans, missing indexes, inefficient JOINs, N+1 patterns, unnecessary subqueries, or cartesian products.

**Step 3 - Optimized Query**
Provide the rewritten query with inline comments explaining each optimization made.

**Step 4 - Index Recommendations**
Provide the exact CREATE INDEX statements to add, with explanation of why each index helps.

**Step 5 - Expected Performance Improvement**
Estimate the performance gain from each optimization.

**Step 6 - Alternative Approach**
If the query could be fundamentally restructured for dramatically better performance, show the alternative and explain the tradeoff.

help_outline How To Use This Prompt

  1. Click the Copy Prompt button above to copy the prompt text.
  2. Open your preferred AI tool -- Llama 3.
  3. Paste the prompt into the chat input field.
  4. Replace any placeholder text (in [brackets]) with your specific details.
  5. Press Enter and review the AI-generated output.
  6. Refine the prompt as needed for better results.

quiz Frequently Asked Questions

What is the "SQL Query Optimizer and Explainer - Llama 3" prompt used for? expand_more
Paste a slow SQL query and get a full performance analysis, plain-English explanation, and optimized rewrite.
Which AI models work with this prompt? expand_more
This prompt works best with Llama 3. You can also try it with other large language models for similar results.
Can I modify this prompt? expand_more
Yes! Feel free to copy and customize this prompt to better fit your specific needs. You can change names, industries, tones, or any other variables to personalize the output.
Is this prompt free to use? expand_more
Absolutely. All prompts on GetPromptPro are free to copy and use for personal or commercial purposes.