[
https://issues.apache.org/jira/browse/CALCITE-2997?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17106658#comment-17106658
]
Julian Hyde commented on CALCITE-2997:
--------------------------------------
I agree, [~swtalbot]. I have re-opened the issue. It should not have been
closed as 'invalid', because the requirement is a valid ask.
We're making ever more use of RelBuilder in SqlToRelConverter, and RelBuilder
performs various rewrites/optimizations as it goes. Some of these rewrites are
essential for the integrity of {{RelNode}}/{{RexNode}} data structure(e.g. the
assumption that {{(AND x (AND y z))}} is flattened to {{(AND x y z)}}), but
others are deemed "almost certainly beneficial".
This rewrite is of the latter category. We should make it possible to disable
such rewrites individually.
In this case (see
[code|https://github.com/apache/calcite/blob/e44beba286ea9049c5fd00c3a3b0e4a4f1c03356/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java#L2617]),
there is a {{RelBuilder}} involved but the rewrite is done by the
{{SqlToRelConverter}}. The ideal fix would move the rewrite code into
{{RelBuilder}}, and add a config parameter to {{RelBuilder}} so that people can
disable it. Less ideally, we would leave the code in {{SqlToRelConverter}} and
add a config parameter to {{SqlToRelConverter}}.
> Avoid pushing down join condition in SqlToRelConverter
> ------------------------------------------------------
>
> Key: CALCITE-2997
> URL: https://issues.apache.org/jira/browse/CALCITE-2997
> Project: Calcite
> Issue Type: Bug
> Reporter: Jin Xing
> Assignee: Julian Hyde
> Priority: Major
>
> In current code, *SqlToRelConverter:createJoin* is calling
> *RelOptUtil.pushDownJoinConditions* for optimization. And we can find below
> conversion from *SqlNode* to *RelNode*:
> {code:java}
> SqlNode:
> select * from A join B on A.x = B.x * 2
> RelNode (Logical-Plan):
> Join (condition:col0=col1)
> |-Project(x as col0)
> | |-Scan(A)
> |-Project(x * 2 as col1)
> |-Scan(B){code}
> As we can see the logical plan(*RelNode*) posted above is not the pure
> reflection of the original SQL String(*SqlNode*). The optimization is mixed
> into the phase on which AST is converted to Logical-Plan. Actually optimizing
> rule of JoinPushExpressionsRule is doing exactly the same kind of thing.
> Shall we just keep the optimization inside Optimized-Logical-Plan ? I mean
> shall we avoid calling *RelOptUtil.pushDownJoinConditions* in
> *SqlToRelConverter:createJoin*
> I raised this issue because that we are doing something based on the
> Logical-Plan. And it makes us really confused that the Logical-Plan doesn't
> corresponds to SqlNode.
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)