💻 AI SQL Query Optimizer Prompt — Fix Slow Queries Instantly

AI SQL Query Optimizer Prompt — Fix Slow Queries Instantly

Diagnose and fix slow, inefficient SQL queries — with index recommendations, rewritten queries, and performance explanations. Works with PostgreSQL, MySQL, and more.

📋 The Prompt

Act as a senior database engineer and SQL performance specialist with deep expertise in query optimization. Optimize the following SQL query: Database: [PostgreSQL / MySQL / SQLite / SQL Server / BigQuery] Current problem: [e.g. query takes 8 seconds / times out on large datasets / causes high CPU load / returns duplicate results] Current query: [paste your SQL query here] Relevant table structure (paste CREATE TABLE statements or describe): [paste schema here OR describe: "users table with 2M rows, orders table with 10M rows"] Approximate data size: - Table sizes: [e.g. users: 500K rows, orders: 5M rows] - Query frequency: [e.g. runs 1000x per hour / once per day] Please provide: 1. Diagnosis — exactly WHY the current query is slow 2. Optimized query — rewritten for maximum performance 3. Index recommendations: - Which indexes to add (with exact CREATE INDEX statements) - Which existing indexes might be hurting performance 4. Explanation of every change made and the performance impact 5. EXPLAIN ANALYZE output interpretation (if I paste it, analyze it) 6. One alternative approach if further optimization is needed Expected outcome: query should run in under [X seconds/ms]

🚀 How to Use This Prompt

Copy the prompt above and paste it into your preferred AI tool — Midjourney, DALL-E, ChatGPT, or Stable Diffusion. Replace all [bracketed placeholders] with your specific values for best results.

💡 Tips for Best Results

  • Be as specific as possible when filling in the placeholders.
  • Experiment with different values for varied, unique results.
  • For Midjourney, add --v 6 --ar 16:9 at the end.
  • Run the same prompt multiple times — AI generates unique outputs each run.

More Coding Prompts

REST API Builder with Authentication : Build a Complete REST API with Auth — AI Prompt
Coding

REST API Builder with Authentication : Build a Complete REST API with Auth — AI Prompt

Generate a production-ready REST API with JWT authentication, input validation, and error ...

Open →
Production-Ready AI Coding Prompt
Coding

Production-Ready AI Coding Prompt

A focused AI coding prompt built for real production systems. It pushes the AI to think li...

Open →
AI Code Security Audit Prompt — Find Vulnerabilities Before Hackers Do
Coding

AI Code Security Audit Prompt — Find Vulnerabilities Before Hackers Do

Scan your code for security vulnerabilities, SQL injection risks, authentication flaws, an...

Open →