zhuqi-lucas opened a new issue, #21700:
URL: https://github.com/apache/datafusion/issues/21700

   ## Is your feature request related to a problem or challenge?
   
   When an Extension node (e.g. view matching OneOf) has many children but no 
expressions, `LogicalPlan::map_expressions` still clones all inputs and calls 
`with_exprs_and_inputs` to reconstruct the node — wasted work since there are 
no expressions to transform.
   
   In our production system with view matching (5 MV candidates × ~15 optimizer 
rules), this unnecessary rebuild is the dominant cost of the optimizer pass for 
plans containing Extension nodes.
   
   ## Describe the solution you'd like
   
   Add an early return in `map_expressions` when `node.expressions()` is empty:
   
   ```rust
   LogicalPlan::Extension(Extension { node }) => {
       let raw_exprs = node.expressions();
       if raw_exprs.is_empty() {
           Transformed::no(LogicalPlan::Extension(Extension { node }))
       } else {
           // existing clone + rebuild path
       }
   }
   ```
   
   ## Describe alternatives you've considered
   
   None — the change is straightforward and safe. Empty expressions means no 
transform is needed.
   
   ## Additional context
   
   Benchmark results (criterion micro-benchmark):
   
   | Children | no_expr (optimized) | with_expr (rebuild) | Speedup |
   |----------|--------------------|--------------------|---------|
   | 1        | 24 ns              | 167 ns             | 7x      |
   | 3        | 23 ns              | 192 ns             | 8x      |
   | 5        | 23 ns              | 181 ns             | 8x      |
   | 10       | 24 ns              | 216 ns             | 9x      |
   
   The `no_expr` path is constant time regardless of children count.


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to