AI prompts for Developers
Prompt to speed up a slow SQL query
Reads the query and its EXPLAIN plan, then suggests rewrites and indexes with the trade-off of each.
When to use it When a page or report is slow because of a query and you want the cause before adding indexes at random.
The prompt, ready to copy
Role: database performance specialist. Task: analyse why the query is slow and suggest improvements. Context: - Database system and version: [system] - Rough table sizes: [rows per table] - Current time and acceptable time: [e.g. 8 seconds, target under 1] Query and plan: <source> [The query, EXPLAIN or EXPLAIN ANALYZE output, and existing indexes] </source> Constraints: - Base the analysis on the pasted plan; do not assume indexes that are not listed - Do not promise a specific speed-up; say what should improve and why - State the cost of each proposed index (space, slower writes) - A rewritten query must return exactly the same result Output: 1. Where time is spent, per the plan 2. Improvements in order: change | reason | cost 3. Rewritten query if needed 4. How to measure the difference
Example of filled brackets
Database: MySQL 8 Sizes: orders about 2 million rows, customers about 200,000 Time: 6 seconds in the daily sales report Source: the query, EXPLAIN output, and index list
Check these before you use it
- Measure before and after on data close to production size
- Add indexes in production at a low-traffic time
How to use this prompt
- Copy the prompt: Press the copy button or select the whole text.
- Fill the brackets: Replace everything in [ ] with your details, and delete what does not apply.
- Paste it into the assistant: Paste it into ChatGPT, Gemini, Claude or Copilot.
- Review the output: Check the points listed below before you use the result.