SQL Tuning: Read the Execution Plan First
Point out where it is slow, then give indexing or rewrite options
Prompt
Copy it whole, then replace the brackets with your own contentCode task: SQL optimization, look at the execution plan first. Code/error: [paste] Environment: [language/version/framework] Requirements: point out where it is slow, then give an index or rewrite plan. Give your diagnosis first, then the changes, then how to verify.
Replace the text in [ ] with your own situation; ask long tasks in stages.
How to get better results
Read this before you fill it inFor queries over 1 second, or still slow after adding indexes.
Give the conclusion and impact scope first, then only the changed snippets (no full files), and finally one check that proves it works. Flag risky spots separately.
This query takes 3.2s: select ... from orders where status=? and created_at>? order by id desc limit 20 The table has 20M rows and status has only 5 values.
No execution plan, so index advice is guesswork No data volume given, so the plan may be overkill Optimizing one query while ignoring write cost
If problems remain after the fix, paste the new error and the changed snippet back; keep debugging on the original approach, don't switch approaches and rewrite.
More like this: Writing code prompts · All prompts