Hi all,

In light of CALCITE-2970, I’d like to initiate a discussion.

Currently the framework itself does not have a way to create physical RelNode 
(RelNode with a particular convention). We completely rely on adapter rules to 
convert logical nodes into physical ones. There are a few major drawbacks with 
this approach -

1. During trait enforcement, we have to create logic node and then get it 
implemented by converter rule, even though we know the target convention. This 
results in the increase of memo size and planning time. CALCITE-2970 is one 
good example.

2. A lot of implementation rules today simply copy the inputs and create a 
physical node (examples like EnumerableProjectRule, EnumerableFilterRule, etc). 
If the framework was able to create physical node, a lot of these trivial rules 
could be eliminated.

3. There are a number of adapter rules today using RelBuilder and creating 
logical node. This is not desirable since in a lot of cases what they need are 
physical nodes instead. Creating logical nodes then getting them implemented by 
converters again is inefficient.

To solve this problem, there have been two proposals so far -

a) Extend current RelBuilder interface to support withConvention() syntax, 
which means you could build a physical node with the convention specified. This 
can be done through extending the RelNode factory withheld by the builder. 
Calcite user can register a particular factory for their own convention.

b) Extend Convention interface and add something like "RelNode enforce(RelNode 
input, RelTrait trait)". This would be used to address issue #1. A convention 
could implement this method to create exact physical node to be used for 
satisfying given trait.

I personally prefer a) since I believe this is a basic building block and it’s 
not just for enforcement. Also extending RelBuild feels nature to me - the 
intention was clearly there when this class was created (look at the class 
comments). There have been discussions about whether or not RelBuilder should 
support creating physical nodes. Although we have been using it solely for 
logical nodes building today, but that doesn’t mean we shouldn’t extend to 
physical ones. I haven't seen clear reasoning.

Would like to hear your thoughts.

Reply via email to