Ad space (top)
Home β€Ί Prompt Library β€Ί Prompt to Optimize a Slow SQL Query

Prompt to Optimize a Slow SQL Query

Get the AI to diagnose and speed up a slow query with indexes and rewrites.

Coding Β· Works great in Any AI

Copy-ready prompt

Optimize this slow SQL query for [database].
```
[paste query]
```
Schema and sizes: [tables, row counts, existing indexes].
Requirements:
- Explain what's likely making it slow.
- Suggest index changes and query rewrites.
- Provide an optimized version.
- Note trade-offs of each suggestion.

Want a version tailored to you?

Answer a few quick questions and the SQL Query Generator builds a custom prompt from your exact details.

πŸ—„οΈ Open the SQL Query Generator
Ad space (inline)

Why this prompt works

Query tuning depends on schema, data volume, and indexes β€” details the AI can't guess. Provide them and this prompt can pinpoint the bottleneck and propose rewrites plus indexes, with trade-offs so you don't fix speed at the cost of write performance.

How to customize it

  • Include row counts and existing indexes; they drive the diagnosis.
  • Test suggested indexes on a copy β€” they add write overhead.
  • Compare execution plans before and after.

Tip: replace the parts in [square brackets] with your own details before you send. The more specific you are β€” audience, tone, goal, constraints β€” the better the AI output.

Ad space (sidebar)