query-optimization
Installation
SKILL.md
Query Optimization Skill
Phase 1 — Discovery
Ask only what context doesn't reveal:
- Database engine and version? Planner behavior, available hints, and index types differ significantly. Postgres 14+ has improved parallel query and CTE materialization defaults vs. older versions.
- Do you have
EXPLAIN ANALYZEoutput? Without it, optimization is guesswork. Ask them to run it and share — not justEXPLAIN(estimates only), butEXPLAIN (ANALYZE, BUFFERS)which shows actual row counts and I/O. - Table row counts for involved tables? The planner's choices make sense or don't in context of data volume.
- Is this a one-time slow query or a recurring endpoint? One-time queries tolerate different tradeoffs (parallel workers, temp indexes) vs. a hot path that runs thousands of times per minute.
- Are statistics up to date? Ask if
ANALYZEhas been run recently on large tables. Stale statistics cause the planner to make systematically wrong choices.