django-query-plan-reading
Read and compare Django/PostgreSQL query execution plans using QuerySet.explain(), EXPLAIN, EXPLAIN ANALYZE, scan types, joins, estimates, actual timing, buffers, and row counts. Use when one SQL query dominates Django latency or when an index, ORM rewrite, pagination change, or materialized view needs proof from a query plan.
- License 许可
- MIT
- 最近更新
- 2026-06-26
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- django-query-plan-reading
- license
- MIT
- metadata
- { "tags": "django,database,query-plans,postgres,performance", "version": "0.1.0", "category": "Django", "displayName": "Django Query Plan Reading" }
- description
- Read and compare Django/PostgreSQL query execution plans using QuerySet.explain(), EXPLAIN, EXPLAIN ANALYZE, scan types, joins, estimates, actual timing, buffers, and row counts. Use when one SQL query dominates Django latency or when an index, ORM rewrite, pagination change, or materialized view needs proof from a query plan.
- compatibility
- Codex, Claude Code, and other Agent Skills-compatible clients.
02 资源文件 1
- 参考文档references/explain-checklist.md2.5 KB
03 SKILL.md 正文
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.
- Use
-
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.
- Missing selective access path: use
-
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 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.
04 同仓库更多 Skills
android-emulator-qa
Use when validating Android feature flows in an emulator with adb-driven launch, input, UI-tree inspection, screenshots, and logcat capture.
supabase-postgres-best-practices
Postgres performance optimization and best practices from Supabase. Use this skill when writing, reviewing, or optimizing Postgres queries, schema designs, or database configurations.
sentry
Use when the user asks to inspect Sentry issues or events, summarize recent production errors, or pull basic Sentry health data via the Sentry API; perform read-only queries with the bundled script and require `SENTRY_AUTH_TOKEN`.
render-workflows
Sets up, develops, tests, and deploys Render Workflows. Covers first-time scaffolding (via CLI or manual), SDK installation (Python or TypeScript), task patterns (retries, subtasks, fan-out), local development, Dashboard deployment, and troubleshooting. Use when a user wants to set up Render Workflows for the first time, scaffold a workflow service, add or modify workflow tasks, test workflows locally, or deploy workflows to Render.
render-web-services
Configures Render web services—port binding, TLS, health checks, custom domains, auto-deploy, PR previews, persistent disks, and deploy lifecycle. Use when the user needs to set up a web service, fix health check failures, add a custom domain, configure zero-downtime deploys, or troubleshoot port binding issues.
render-static-sites
Deploys and configures static sites on Render's global CDN—build commands, publish paths, SPA routing, redirects, custom headers, and PR previews. Use when the user needs to deploy a static site, set up a React/Vue/Hugo/Gatsby frontend, configure SPA fallback routing, add redirect rules, customize response headers, or choose between a static site and a web service for their frontend. Trigger terms: static site, CDN, SPA, single-page app, React deploy, Vue deploy, Hugo, Gatsby, Docusaurus, Jekyll, staticPublishPath.