polardb/polardbx-sql/polardbx-plan-analysis
- community
Checking that the SKILL.md file is still in the repository.
Analyze PolarDB-X execution plans or determine semantic equivalence between SQL and execution plans. Covers EXPLAIN / EXPLAIN COST / EXPLAIN ANALYZE operator interpretation, cost estimation analysis, runtime statistics bottleneck identification, SQL-to-plan equivalence verification, and optional Graphviz plan visualization. Use when analyzing execution plans on PolarDB-X, interpreting operator behavior, checking plan cost/performance, or verifying SQL-plan semantic equivalence. Triggers: "plan analysis", "执行计划分析", "explain output", "explain cost", "explain analyze", "operator meaning", "算子含义", "equivalence analysis", "等价性分析", "plan equivalence", "计划是否等价", "sql and plan consistency", "sql和plan是否一致", "cost analysis", "代价分析", "rowcount deviation", "rowcount偏差", "draw plan", "画计划图", "plan visualization", "计划可视化"
Install
npx vskill@latest install polardb/polardbx-sql/polardbx-plan-analysisSKILL.md
PolarDB-X Execution Plan Analysis
Analyze PolarDB-X execution plans (EXPLAIN / EXPLAIN COST / EXPLAIN ANALYZE output) and verify semantic equivalence between SQL and execution plans.
Scope
Applies to:
- Operator interpretation of
EXPLAIN/EXPLAIN COST/EXPLAIN ANALYZEoutput EXPLAIN COSTcost estimation (rowcount, cumulative cost) interpretationEXPLAIN ANALYZEruntime statistics (actual time, actual rowcount, instances) interpretation and bottleneck identification- SQL-to-execution-plan semantic equivalence verification
- Foundation for phase/rule-level optimizer attribution analysis (operator interpretation capabilities)
Does NOT apply to:
- Optimizer rule tuning or phase-level attribution analysis
- SQL rewriting or query optimization suggestions
- Index recommendation or schema design (use
sql-revieworpolardbx-sql) - Non-PolarDB-X EXPLAIN output (MySQL, PostgreSQL, etc.)
- DN-level (storage node) internal execution details
Verification — confirm you are working with PolarDB-X EXPLAIN output:
Mode 1: Plan Interpretation
Workflow
- Receive input — User pastes EXPLAIN output. If not provided, guide them to run
EXPLAIN <sql>/EXPLAIN COST <sql>/EXPLAIN ANALYZE <sql> - Identify mode — Contains
rowcount =-> EXPLAIN COST; containsactual time =-> EXPLAIN ANALYZE. Seereferences/explain-cost-analyze.mdfor field definitions - Parse plan tree — One operator per line, indentation indicates parent-child relationship, operator name is the text before the first
( - Separate metadata — Identify non-operator lines at the end of the plan tree (
HitCache:,Source:,TemplateId:, etc.), process them separately as metadata - Classify operators — Match against
references/operator-taxonomy.mdinto 17 categories (note: display names may differ from class names, see mapping table) - Interpret each operator — Explain bottom-up: name, category, function, key attributes. See corresponding reference files for operator attribute definitions
- Cost/performance analysis (COST/ANALYZE mode) — rowcount deviation, actual time bottlenecks, instances, spill
- Plan description — One paragraph summarizing data flow (scan -> output), stating plan type and key strategies
- Metadata interpretation — Parse HitCache/Source/TemplateId/BaselineInfo fields, provide cache hit and plan source conclusions
Output Format
Output three sections (four when metadata is present): Raw Plan -> Plan Description -> Operator Analysis -> Plan Metadata (if applicable).
Raw Plan Line Numbering Rules
- Lines are numbered sequentially starting from 1
- Line numbers are right-aligned with space padding (e.g.,
1,10) - Two spaces follow the line number, then the original indentation and operator text
- Example:
`` 1 Exchange(distribution=single, collation=[]) 2 Project(promo_revenue="?0 * $f0 / $f1") 3 HashAgg($f0="sum($f0)", $f1="sum($f1)") ``
Plan Description Requirements
- State the plan type at the beginning: Columnar / MPP / SMP
- Trace data flow bottom-up, describe in actual flow order
- Use specific column names and values: annotate shuffle partition count like
shuffle by l_partkey to 96 partitions - Specify join roles: which side builds the hash table, whether partition-wise
- Annotate key strategies: two-phase aggregation, broadcast small table, large table stays in place
- Appropriate sentence breaks: 2-4 operation steps per sentence, separated by periods
- Annotate key nodes with
(L<line_number>)referencing the raw plan line number for quick lookup. Annotation targets include: Exchange/shuffle, join, aggregation, sort, and other key operators; not every operator needs annotation, only those helpful for understanding data flow
Operator Analysis Requirements
- Listed in original plan order (root to leaf)
- Append
Input: #Nat the end of the description to indicate data source line number - Dual-input operators annotated as
Input: #N, #M - Leaf nodes have no input annotation
Example
Input plan:
Output:
More plan description examples:
- "Columnar execution plan. Filters region(L15) then broadcasts(L14), joins with nation(L13) then broadcasts(L12), customer joins the result(L11). Orders filtered by date, shuffled by o_custkey to 96 partitions(L8) to join customer result(L7), then shuffled by o_orderkey to 96 partitions(L5) to join lineitem(L4). Supplier broadcasts(L3), joins via suppkey + nationkey(L2), two-phase agg groups by n_name, sorts by revenue for output(L1)."
- "Columnar execution plan. Orders filtered by date(L7), partition-wise semi hash join with lineitem(L5). Two-phase agg(L3,L4) counts by o_orderpriority, sorts for output(L1)."
- "SMP execution plan. Orders and lineitem pushed down to DN for join and partial aggregation(L4,L5), Gather(L3) collects results, CN performs final HashAgg(L2), TopN(L1) returns top 10."
Plan Metadata Parsing
EXPLAIN output may include metadata lines at the end (HitCache, Source, TemplateId, etc.). These lines are not part of the operator tree, are not included in line numbering, and are interpreted separately in a ## Plan Metadata section after the operator analysis table.
See references/plan-metadata.md for field definitions, Source enum values, output format, and interpretation guidelines.
Mode 2: Equivalence Analysis
Workflow
- Receive input — Obtain the SQL and corresponding EXPLAIN plan
- Check each dimension — Verify bottom-up along the 14 dimensions defined in
references/equivalence-analysis.md - Output conclusion — Per-dimension verdict; when not equivalent, specify location and reason
14 Analysis Dimensions
| # | Dimension | Core Checkpoints | |
|---|---|---|---|
| 1 | Filter conditions | WHERE/HAVING predicate completeness, operator direction | |
| 2 | Column references & projection | Project expressions match SELECT list, column index misalignment | |
| 3 | JOIN conditions & type | condition + type (inner/semi/anti/left/right) | |
| 4 | Aggregation | GROUP BY column set, function type, DISTINCT | |
| 5 | Sort & LIMIT | ORDER BY direction, LIMIT/OFFSET, two-phase TopN | |
| 6 | Exchange/Shuffle | Distribution strategy ensures no data loss or duplication | |
| 7 | Subquery decorrelation | CorrelateApply -> Semi/Anti Join transformation correctness | |
| 8 | CTE | projects/conditions column indices, execution order | |
| 9 | Window functions | PARTITION BY, ORDER BY, function, frame boundary | |
| 10 | Set operations | UNION ALL vs DISTINCT, column compatibility | |
| 11 | TableScan pushed-down SQL | sql field contains correct push-down logic | |
| 12 | Parameterization restoration | ?N corresponds to original literal values | |
| 13 | Expand | GROUPING SETS expansion and groupId | |
| 14 | TableLookup | Lookup condition and output column completeness |
Output Format
Plan Visualization (Optional)
Only execute when the user explicitly requests "draw", "visualize", or similar. Do not draw by default.
See references/plan-visualization.md for details.
EXPLAIN Display Name -> Operator Class Mapping
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingpolardbx-executor/src/main/resources/ai/skills/polardbx-plan-analysis/SKILL.md
Popularity
- Repository stars
- 1,687
- Repository forks
- 338
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/polardb/polardbx-sql/polardbx-plan-analysis)