[ 
https://issues.apache.org/jira/browse/CALCITE-3972?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17101043#comment-17101043
 ] 

Julian Hyde commented on CALCITE-3972:
--------------------------------------

[~xndai] wrote:

bq. Also the RelBuilder is not immutable today. The stack can change after it's 
passed into a function. So it's not a new problem...

I acknowledged that earlier in the comment thread. The stack of {{RelNode}}s 
(and ancillary data like aliases) is mutable. The config is not mutable. This 
is intentional - I consider config and the rel stack to be different classes of 
state.

Any class called 'builder' of course has mutable state. Builders are useful 
because they allow mutation in a controlled way. 

bq. I mean with the adoptConvention() we create a new builder every time. It 
could be problematic if this gets call frequently (such in high frequent rules).

Creating a {{RelBuilder}} is fairly efficient - 7 fields to assign, two object 
creations ({{ArrayDeque}} and {{RexSimplify}}). A typical planning process 
might fire 10k rules. 10k object creations is not going to move the dial.

> Allow RelBuilder to create RelNode with convention and use it for trait 
> convert
> -------------------------------------------------------------------------------
>
>                 Key: CALCITE-3972
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3972
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Xiening Dai
>            Assignee: Xiening Dai
>            Priority: Major
>             Fix For: 1.23.0
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> 1. Provide Convention.transformRelBuilder() to transform an existing 
> RelBuilder into one with specific convention.
> 2. RelBuilder provides withRelFactories() method to allow caller swap the 
> underlying RelFactories and create a new builder. 
> 3. Use the new interface in RelCollationTraitDef for converting into 
> RelCollation traits
> We can avoid ~1/3 of total rule firings in a N way join case with this change.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to