SQL Optimization Advisor

What This Prompt Does:

Fix slow queries and optimize database performance. This prompt analyzes your SQL code and execution plan to suggest better indexing, query restructuring, and resource-saving tweaks.

Key Tips for Best Results:

  • Paste the ‘EXPLAIN ANALYZE’ output if you have it.
  • Specify your SQL dialect (PostgreSQL, MySQL, SQL Server, etc.).
  • Mention the size of the tables involved.

Description

About This Prompt: SQL Optimization Advisor

Optimized for:
ChatGPT
Claude
Gemini
Grok
Verified precision.

How To Use The Prompt:

  1. Copy the entire prompt from the window and paste it directly into ChatGPT, Claude, or Gemini.
  2. Locate and replace the main placeholders with your specific details: [SQL DIALECT], [SLOW QUERY], and [TABLE SCHEMA].
  3. Input Example: Use the following format for your input:

Example Input: Dialect: PostgreSQL, Problem: Join takes 10s on 1M rows, Query: [Paste Here].

Additional Information:

A single slow query can kill app performance. This prompt helps you find the ‘low hanging fruit’ in your database logic.

This prompt provides the foundation to:

  • Speed: Significantly reduces query execution time.
  • Resource Efficiency: Lowers CPU and memory usage on your DB server.
  • Knowledge: Teaches you how to write more efficient SQL in the future.

Safety Note: As a professional colleague, always review AI-generated assessments for potential bias or inaccuracies before making final business or management decisions.

PROMPT WINDOW

You are a Senior Database Administrator and Performance Tuning Expert. I have a [SLOW QUERY] in [SQL DIALECT] that is underperforming.

Review the query and the provided [TABLE SCHEMA].
Identify:
1. Why the query is slow (missing indexes, full table scans, etc.).
2. An optimized version of the query.
3. Specific DDL commands (like CREATE INDEX) that would improve performance.

Explain your logic clearly.