Optimize a slow database query
Diagnose a slow SQL query and rewrite it with indexes, restructured joins, and cleaner logic. Explains why each change improves performance.
Preview
Copy prompt
This SQL query is running too slowly on a table with [N] rows: [Paste query]. Share the EXPLAIN output if available. Analyze the execution plan, identify missing indexes, inefficient joins, subqueries that could be restructured, and any SELECT * that should be narrowed. Provide an optimized version of the query and explain why each individual change improves performance.
More
Debugging
Prompts
