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

   ## Motivation
   
   `IterativeOptimizer` logs every rule application at DEBUG level, but the 
before/after plan slots were filled with empty strings:
   
   ```java
   LOG.debug(DataNodeQueryMessages.RULE_S_BEFORE_S_AFTER_S, 
rule.getClass().getName(), "", "");
   ```
   
   The message template is `"Rule: {}\nBefore:\n{}\nAfter:\n{}"`, so enabling 
`DEBUG` for this logger produced a rule name followed by two blank sections — 
the log existed but carried no diagnostic value. This is a leftover from the 
initial table-model port; the placeholders were never filled in (verified via 
`git log`: they were already empty before the i18n conversion of this literal).
   
   ## Changes
   
   - **`IterativeOptimizer`**: render the node being rewritten and the 
transformed plan with the existing `PlanGraphJsonPrinter`, and pass them into 
the log.
   - **`PlanGraphJsonPrinter`**: treat `GroupReference` as a leaf. 
Optimizer-internal nodes have `GroupReference` children, and 
`GroupReference.getChildren()` throws `UnsupportedOperationException`, which 
made both plan printers fail on such plans. This is a no-op for EXPLAIN, where 
group references never appear.
   - Rule timing is now taken **before** logging, so enabling DEBUG no longer 
inflates the recorded rule execution time.
   
   Rendering is best-effort and debug-gated: if rendering throws, the log falls 
back to the node's `toString`, so a debug log can never fail a query.
   
   ## Example output
   
   With `DEBUG` enabled for 
`org.apache.iotdb.db.queryengine.plan.relational.planner.iterative.IterativeOptimizer`:
   
   ```
   Rule: ...rule.InlineProjections
   Before:
   {
     "name": "ProjectNode-8",
     "id": "8",
     "properties": {
       "OutputSymbols": ["device_id$gid", "count"],
       "Expressions": ["\"device_id$gid\"", "\"count\""]
     },
     "children": [{ "name": "GroupReference-19", "id": "19" }]
   }
   After:
   {
     "name": "ProjectNode-8",
     ...
     "children": [{ "name": "GroupReference-20", "id": "20" }]
   }
   ```
   
   ## Test plan
   
   - `PlanGraphJsonPrinterTest` — added `testGroupReferenceIsRenderedAsLeaf`, 
which renders a plan whose child is a `GroupReference` and asserts it is 
emitted as a leaf and that rendering does not throw.
   - Ran `PlanGraphJsonPrinterTest`, `PlanGraphPrinterTest` and 
`TableModelPlannerTest`: 21 tests, 0 failures.
   - End-to-end: built the distribution, enabled the DEBUG logger, ran a 
table-model query with a subquery; all 13 rule applications rendered real 
plans, with no fallback and no exception in the server log.
   
   🤖 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