You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "zhuqi-lucas (via GitHub)" <gi...@apache.org> on 2026/04/17 15:17:59 UTC

[I] Skip map_expressions rebuild for Extension nodes with empty expressions [datafusion]

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: github-unsubscribe@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Skip map_expressions rebuild for Extension nodes with empty expressions [datafusion]

Posted by "zhuqi-lucas (via GitHub)" <gi...@apache.org>.
zhuqi-lucas closed issue #21700: Skip map_expressions rebuild for Extension nodes with empty expressions
URL: https://github.com/apache/datafusion/issues/21700


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org