Review and optimize a SQL query
Paste a slow or suspicious SQL query and get correctness checks, performance fixes, and a cleaner rewrite you can verify.
Find why a query is slow and get a faster version, index suggestions and a way to prove the improvement.
Help me speed up a slow {{dialect}} query.
Query:
{{query}}
Execution plan (EXPLAIN / EXPLAIN ANALYZE output), if I have it:
{{plan}}
Table sizes and existing indexes:
{{tables}}
How slow it is and what is acceptable: {{target}}
Please:
1. Diagnose: explain in plain words what the database is doing and where the time goes. If a plan is provided, cite specific nodes (seq scans, sorts, nested loops, bad row estimates). If not, say what you suspect and ask me to run EXPLAIN ANALYZE, showing the exact command.
2. Rank the fixes by expected impact: query rewrite, new or changed indexes, schema or statistics changes, and application-side changes such as pagination or caching.
3. Show the rewritten query and the exact CREATE INDEX statements, with the column order justified.
4. Warn about tradeoffs: write cost of new indexes, locking during creation, and whether the rewrite returns exactly the same rows.
5. Give me a way to verify: what to compare before and after.
Do not suggest rewrites that change the results unless you flag it clearly.Asking for the plan, and for the exact EXPLAIN command when it is missing, anchors advice in evidence rather than generic tips. Requiring same-result rewrites keeps optimizations safe.
Licensed CC0 (public domain) Version 1 · history
Paste a slow or suspicious SQL query and get correctness checks, performance fixes, and a cleaner rewrite you can verify.
Turn feature requirements into a normalized schema with keys, constraints, indexes and the tradeoffs explained.
Paste a profile, flame graph summary or timings and get a ranked list of real bottlenecks with what to try first.
Describe the question and your tables, and get a correct, readable query with an explanation and edge cases.
Describe your tables and the question you need answered and get a correct, commented SQL query with assumptions spelled out.
Set up a proper cohort retention analysis, from defining cohorts and the activity event to producing the table and reading it correctly.
Comments (0)
Sign in to join the discussion.
No comments yet. Be the first to share how it worked.