django-query-plan-reading
Read and compare Django/PostgreSQL query execution plans using QuerySet.explain(), EXPLAIN, EXPLAIN ANALYZE, scan types, joins, estimates, actual ti…
它会碰到什么
扫了多少2 个文本文件,5 KB
它会碰到什么不碰外部(只输出文字)
命中总数0 处
命中统计严重 0 · 高 0 · 中 0 · 低 0
这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。
技能内容
Django Query Plan Reading
Use this skill when the expensive unit is a specific SQL statement or queryset. The goal is to explain why the database is doing work, not to guess from the ORM code.
Workflow
- Get the exact query.
- Prefer the queryset that produced it.
- If starting from logged SQL, include bound parameters or representative literals.
- Generate a plan.
- Use
queryset.explain()for ORM-owned SQL. - Use database
EXPLAINfor raw SQL, views, materialized views, or SQL copied from logs. - Use
analyze=Trueonly in a safe environment because the database executes the query.
- Read from the deepest node outward.
- Identify table scans, index scans, joins, sorts, aggregations, and limits.
- Compare estimated rows with actual rows when using analyze.
- Look for high-cost nodes that feed many rows to later nodes.
- Decide the next change.
- Missing selective access path: use
django-index-design. - Query shape prevents useful index access: rewrite filters, ordering, or join strategy.
- Large unavoidable aggregation: consider
django-db-side-computationordjango-materialized-views. - Deep offset cost: use
django-pagination-performance.
- Re-run the same plan after the change.
- Compare scan type, row counts, sort nodes, heap fetches, buffers, planning time, and execution time.
See [explain-checklist.md](references/explain-checklist.md) for plan-reading cues and before/after review notes.
Safety Notes
EXPLAIN ANALYZEexecutes the query. Avoid it for mutations, unsafe functions, and production paths unless you know the impact.- A sequential scan is not automatically bad. It can be best when the table is small or the predicate returns much of the table.
- A used index is not automatically good. Random heap access, bad cardinality estimates, or a post-index sort can still dominate.
Verification
Finish with the before/after plan excerpt and a plain explanation of which node changed and why that matters.
想直接用这个技能?
本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。
它属于哪个仓库
星标★ 1,027
本站分层T1
该仓技能数1910
原文件路径
plugins/LVTD-LLC/skills/skills/django-query-plan-reading/SKILL.md