ColinLeeo opened a new pull request, #19139:
URL: https://github.com/apache/iotdb/pull/19139

   ## Motivation
   
   The table-model iterative optimizer already instruments every rule 
application. `IterativeOptimizer` records invocations, applications, elapsed 
time and failures into a `PlanOptimizersStatsCollector`, and 
`IterativeOptimizer.optimizeAndMarkPlanChanges` merges each optimizer's 
internal collector into the one passed through `PlanOptimizer.Context`.
   
   But the collector was created **inside** the planning loops:
   
   ```java
   // TableLogicalPlanner
   new PlanOptimizer.Context(..., 
PlanOptimizersStatsCollector.createPlanOptimizersStatsCollector())
   
   // TableDistributedPlanner — a second, separate collector
   new PlanOptimizer.Context(..., 
PlanOptimizersStatsCollector.createPlanOptimizersStatsCollector())
   ```
   
   Each optimizer call got a fresh collector, and all of them were dropped when 
planning finished. `getTopRuleStats()` had no caller outside the optimizer's 
own timeout message, and `RuleStatsRecorder.getStats()` had **no caller at 
all** — the instrumentation cost was paid on every query and the data was never 
seen.
   
   ## Changes
   
   - **`MPPQueryContext`**: holds the per-query collector 
(`getOrCreatePlanOptimizersStatsCollector()` / 
`getPlanOptimizersStatsCollector()`). A tree-model query never creates one.
   - **`TableLogicalPlanner` / `TableDistributedPlanner`**: create the 
collector once per query and share it between the logical and the distributed 
optimizers, instead of one throwaway collector per call.
   - **`FragmentInstanceStatisticsDrawer` / 
`FragmentInstanceStatisticsJsonDrawer`**: render the top ten rules by total 
time.
   - **`QueryPlanOptimizerStatistics`**: adds `simpleRule()` so the output 
shows `InlineProjections` instead of the full canonical name.
   - Two `DataNodeQueryMessages` constants (en + zh) for the new output lines, 
following the i18n convention.
   
   ## Example output
   
   ```
   Logical Optimization Cost: 45.844 ms
   Top Optimizer Rules:
     InlineProjections: 8 invocations, 2 applied, 2187 us
     PruneProjectColumns: 8 invocations, 2 applied, 1886 us
     ProjectExpressionRewrite: 7 invocations, 0 applied, 1431 us
     ...
   ```
   
   `EXPLAIN ANALYZE (FORMAT JSON)` gets the same data as an 
`optimizerRuleStats` array (`rule`, `invocations`, `applied`, `totalTimeUs`, 
`failures`).
   
   ## Test plan
   
   - New `OptimizerRuleStatsTest`: plans a table-model aggregation query and 
asserts the collector is present on the query context, is shared between 
logical and distributed optimizers, and contains statistics.
   - `OptimizerRuleStatsTest`, `PlanGraphJsonPrinterTest`, 
`TableModelPlannerTest`: 20 tests, 0 failures.
   - Compiled both locales (`mvn test-compile -DskipTests` and `-P 
with-zh-locale`), both `BUILD SUCCESS`.
   - End-to-end: built the distribution, ran `EXPLAIN ANALYZE` and `EXPLAIN 
ANALYZE (FORMAT JSON)` on a table-model aggregation query — the text section 
and the JSON array are both populated (verified output above).
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to