← Prompt library
CodingFree→ Claude / ChatGPT

SQL Query Optimizer

Find the slow part, suggest indexes and rewrite — with the trade-offs explained.

What you get: A diagnosis from the plan, index recommendations and a rewritten query.

input
output — Claude / ChatGPT
Optimize this {{database}} query. Table sizes: {{table_sizes}}.

Schema (relevant tables and indexes):
{{schema}}

Query:
{{query}}

Execution plan (if available):
{{explain_output}}

Explain where the time is going in plain language. Then give: index recommendations with the exact CREATE INDEX statements and the write-cost trade-off; a rewritten query that returns identical results (prove equivalence or state assumptions); whether pagination, covering indexes, materialization or caching would help more than rewriting; and how to verify the improvement safely on production-like data. Warn me if the fix changes semantics.