💻 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

The Ultimate AI Bug Debugging Prompt
Coding

The Ultimate AI Bug Debugging Prompt

Solve coding problems faster and identify the true root cause of software bugs with this a...

Open →
AI Code Refactoring Prompt — Clean Up Messy Code Instantly
Coding

AI Code Refactoring Prompt — Clean Up Messy Code Instantly

Transform messy, unreadable, or inefficient code into clean, maintainable, production-read...

Open →
AI Database Schema Designer — SaaS & App Projects
Coding

AI Database Schema Designer — SaaS & App Projects

Generate an optimized, production-ready database schema for any app or SaaS project — wi...

Open →