Find the Django ORM code and request path responsible for slow SQL by using APM traces, slow query logs, Django Debug Toolbar, query logging, and local reproduction.
SkillScore68Maintained
Automatic
◆Coding pack
Last verified 8/15/2026
What it changes
Passed 14 of 21 test cases with the skill, and 9 of 21 without it.
Without skill41%
With skill68%
Checks it passed that the model alone missed
Requires specifying a named queryset and re-runnable command.
Routes single slow SQL query fixes to django-query-plan-reading.
Recommends disabling debug middleware during timing measurements.
and 6 more in the full report
8 fixed7 passed either way5 still failing2 broke
Pass-rate lift
+27 pp
Tokens
-11%
Agent turns
0%
Response time
-35%
Model gemini-3.6-flashMeasured 8/15/2026v115 of 22 cases passed with skill · 21 comparable
Tokens, turns and time describe resource use, not a dollar price.
See it in action
One of 7 test cases the skill fixed. Same model, same prompt, with and without the skill.
1 of 7
Prompt
Profiling revealed that rendering the order history table executes 250 separate SELECT queries due to un-prefetched relational attributes in template tags. Once this profiling task is complete, where should the fix work be routed?
What was checked, without and with the skill
Checked
Without skill
With skill
Routes the query count optimization to django-orm-query-optimization.
Missed
Passed
case-09 · gemini-3.6-flash · 8/15/2026 · answers are capped and redacted
What's inside
The instructions your model reads when the skill loads.
SKILL.md43 lines2 files
Django Query Profiling
Use this skill to turn a vague slow-Django report into a specific queryset, SQL statement, and reproducible scenario.
Workflow
Start from the user-visible slow path.
Record the URL, API action, background task, management command, or report.
Capture request parameters, user or tenant shape, pagination state, and data volume.
Collect production or staging evidence.
Prefer APM transaction traces when available.
Use database slow-query logs for SQL that is slow independent of Python.
Use Django Debug Toolbar for server-rendered pages in local development.
For APIs or jobs, add targeted query logging around the suspicious block.
Map SQL back to Django code.
Search model table names and column names.
Inspect view get_queryset(), serializer fields, template loops, managers, model properties, and signal handlers.
Check whether related-object access happens after the initial queryset was evaluated.
Reproduce locally or in a safe shell.
Use production-like row counts when possible.
Disable unrelated instrumentation and debug-only middleware when measuring.
Keep a repeatable script, test, or shell snippet that exercises the slow path.
Route the fix.
Query count issue: use django-orm-query-optimization.
One slow SQL statement: use django-query-plan-reading.
Large loops or writes: use django-queryset-batch-processing.
See tooling-and-reproduction.md for concrete profiling snippets and pitfalls.
Good Evidence
Query count before/after for the specific path.
The slow SQL or normalized SQL fingerprint.
Stack or code pointer that explains where the SQL originates.
Timing from the same environment and representative data shape.