polardbx-plan-analysis
Skill8 starsChanged 29 days agoApache-2.0View on GitHub
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", "计划可视化"
In this repository11 other files it gives its agents.
- AGENTS.mdAGENTS.md
- polardbx-cciSkill
- polardbx-cclSkill
- polardbx-online-ddlSkill
- polardbx-opsSkill
- polardbx-paginationSkill
- polardbx-sqlSkill
- polardbx-standardSkill
- polardbx-ttl20Skill
- polardbx-zeroSkill
- sql-reviewSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 94
Use specific column names and values: annotate shuffle partition count like shuffle by l_partkey to 96 partitions
- Distinctive: line 219
Only execute when the user explicitly requests "draw", "visualize", or similar.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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:
SELECT version(); -- should contain "PolarDB-X" or "TDDL"
SHOW STORAGE; -- PolarDB-X specific command, confirms distributed topologyMode 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
<Each line prefixed with line number, format: "line_number operator_text", line numbers right-aligned>
## Plan Description
<One paragraph summarizing data flow, with L<line_number> annotations at key operators for reference>
## Operator Analysis
| # | Operator | Category | Description |
|---|----------|----------|-------------|
| 1 | Project | Project | Computes promo_revenue = 100 * $f0 / $f1. Input: #2 |
| 2 | HashAgg | Agg | Scalar aggregation sum($f0), sum($f1), final stage. Input: #3 |
| ... | ... | ... | ... |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:
Project(promo_revenue="?0 * $f0 / $f1")
HashAgg($f0="sum($f0)", $f1="sum($f1)")
Exchange(distribution=single, collation=[])
PartialHashAgg($f0="sum($f0)", $f1="sum($f1)")
Project($f0="...", $f1="l_extendedprice * ?4 - l_discount")
HashJoin(condition="l_partkey = p_partkey", type="inner")
OSSTableScan(tables="part_col_index[p1,...p96]", shardcount=96, partition=[remote])
Exchange(distribution=hash[0]96, collation=[])
OSSTableScan(tables="lineitem_col_index[p1,...p96]", shardcount=96, sql="... where l_shipdate ...")Output:
## Raw Plan
1 Project(promo_revenue="?0 * $f0 / $f1")
2 HashAgg($f0="sum($f0)", $f1="sum($f1)")
3 Exchange(distribution=single, collation=[])
4 PartialHashAgg($f0="sum($f0)", $f1="sum($f1)")
5 Project($f0="...", $f1="l_extendedprice * ?4 - l_discount")
6 HashJoin(condition="l_partkey = p_partkey", type="inner")
7 OSSTableScan(tables="part_col_index[p1,...p96]", shardcount=96, partition=[remote])
8 Exchange(distribution=hash[0]96, collation=[])
9 OSSTableScan(tables="lineitem_col_index[p1,...p96]", shardcount=96, sql="... where l_shipdate ...")
## Plan Description
Columnar execution plan. Scans lineitem(L9) with l_shipdate filter, then shuffles by l_partkey to 96 partitions(L8), partition-wise hash join(L6) with part(L7). Projects to compute promo/total revenue, then two-phase aggregation (PartialHashAgg(L4) -> Exchange single(L3) -> HashAgg(L2)), finally Project(L1) outputs promo_revenue.
## Operator Analysis
| # | Operator | Category | Description |
|---|----------|----------|-------------|
| 1 | Project | Project | Computes promo_revenue = 100 * $f0 / $f1. Input: #2 |
| 2 | HashAgg | Agg | Scalar aggregation sum, final stage. Input: #3 |
| 3 | Exchange | Exchange | distribution=single, converges to single node. Input: #4 |
| 4 | PartialHashAgg | Agg | Scalar aggregation sum, first stage. Input: #5 |
| 5 | Project | Project | Computes promo revenue and total revenue. Input: #6 |
| 6 | HashJoin | Join | inner, l_partkey = p_partkey. Input: #7, #8 |
| 7 | OSSTableScan | TableScan | part_col_index, 96 shards |
| 8 | Exchange | Exchange | hash[0]96, lineitem shuffled by l_partkey. Input: #9 |
| 9 | OSSTableScan | TableScan | lineitem_col_index, 96 shards, l_shipdate filter |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
## Equivalence Analysis
### Filter Conditions
- Result: Equivalent
- Explanation: ...
### JOIN Conditions & Type
- Result: Not equivalent
- Explanation: ...
## Conclusion
SQL and plan are [equivalent / not equivalent]. [When not equivalent, describe the issue]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
| Display Name | Operator Class | Category |
| LogicalView | LogicalView | TableScan |
| IndexScan | LogicalIndexScan | TableScan |
| OSSTableScan | OSSTableScan | TableScan |
| HashJoin | HashJoin | Join |
| NLJoin | NLJoin | Join |
| BKAJoin | BKAJoin | Join |
| SortMergeJoin | SortMergeJoin | Join |
| SemiHashJoin | SemiHashJoin | Join |
| SemiNLJoin | SemiNLJoin | Join |
| SemiBKAJoin | SemiBKAJoin | Join |
| MaterializedSemiJoin | MaterializedSemiJoin | Join |
| CorrelateApply | LogicalCorrelate | Join |
| ColCorrelate | LogicalColCorrelate | Join |
| LogicalJoin | LogicalJoin | Join |
| LogicalSemiJoin | LogicalSemiJoin | Join |
| LogicalAgg | LogicalAggregate | Agg |
| HashAgg | HashAgg | Agg |
| SortAgg | SortAgg | Agg |
| LogicalSort | LogicalSort | Sort |
| Limit | Limit / LogicalSort | Sort |
| MergeSort | MergeSort | Sort |
| TopN | TopN | Sort |
| MemSort | MemSort | Sort |
| Window | LogicalWindow | Window |
| HashWindow | HashWindow | Window |
| SortWindow | SortWindow | Window |
| Filter | LogicalFilter / PhysicalFilter | Filter |
| Project | LogicalProject / PhysicalProject | Project |
| Calc | LogicalCalc | Project |
| Values | LogicalValues | Values |
| DynamicValues | LogicalDynamicValues | Values |
| TableLookup | LogicalTableLookup | TableLookup |
| Gather | Gather | Exchange |
| Exchange | MppExchange / ColumnarExchange | Exchange |
| LocalBuffer | LocalBufferNode | Exchange |
| CTEAnchor | PhysicalCTEAnchor | CTE |
| CTEProducer | PhysicalCTEProducer | CTE |
| LogicalCTEConsumer | LogicalCTEConsumer | CTE |
| UnionAll | LogicalUnion (all=true) | SetOp |
| UnionDistinct | LogicalUnion (all=false) | SetOp |
| Intersect | LogicalIntersect | SetOp |
| Minus | LogicalMinus | SetOp |
| Expand | LogicalExpand | Expand |
| LogicalInsert | LogicalInsert | DML |
| LogicalModify | LogicalModify | DML |
| LogicalOutFile | LogicalOutFile | OutFile |
| PhyTableOperation | PhyTableOperation | BaseTableOperation |
| RuntimeFilterBuilder | RuntimeFilterBuilder | Other |
References
| File | Content |
references/operator-taxonomy.md | Complete 17-category operator taxonomy |
references/equivalence-analysis.md | 14-dimension equivalence analysis and checking procedure |
references/explain-cost-analyze.md | EXPLAIN COST / ANALYZE cost and runtime statistics fields |
references/plan-metadata.md | Plan metadata (HitCache/Source/TemplateId/BaselineInfo, etc.) |
references/plan-visualization.md | Graphviz plan visualization |
references/join.md | Join operator attributes |
references/agg.md | Agg operator attributes |
references/sort.md | Sort operator attributes |
references/filter.md | Filter operator attributes |
references/project.md | Project operator attributes |
references/exchange.md | Exchange operator attributes |
references/tablescan.md | TableScan operator attributes |
references/window.md | Window operator attributes |
references/cte.md | CTE operator attributes |
references/tablelookup.md | TableLookup operator attributes |
references/setop.md | SetOp operator attributes |
references/expand.md | Expand operator attributes |
references/values.md | Values operator attributes |
references/dml.md | DML operator attributes (INSERT/UPDATE/DELETE/REPLACE) |
references/outfile.md | OutFile operator attributes |
references/other.md | Other operator attributes |
references/rex-explain-visitor.md | RexNode expression display rules |
references/sql-parameterization.md | SQL parameterization rules |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

