You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "James Starr (Jira)" <ji...@apache.org> on 2021/06/25 19:43:00 UTC

[jira] [Updated] (CALCITE-4668) RelBuilder.join should only emit a correlate when a correlate variable exists

     [ https://issues.apache.org/jira/browse/CALCITE-4668?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

James Starr updated CALCITE-4668:
---------------------------------
    Description: 
We generate correlated join when no correlate variable is present on the right side.  However, this could be simplified to emit a normal join.

Given:
{code:java}
final RelNode rel = builder
        .scan("EMP")
        .variable(v)
        .scan("DEPT")
        .join(JoinRelType.LEFT,
            builder.equals(builder.field(2, 0, "SAL"),
                builder.literal(1000)),
            ImmutableSet.of(v.get().id))
        .build();
{code}
Currently the following is emitted:
{code}
LogicalFilter(condition=[=($7, $8)])
  LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{0}])
    LogicalTableScan(table=[[scott, EMP]])
    LogicalFilter(condition=[=($cor0.DEPTNO, $0)])
      LogicalTableScan(table=[[scott, DEPT]])
{code}
After the changes the following will be emitted:
{code}
LogicalJoin(condition=[=($7, $8)], joinType=[left])
  LogicalTableScan(table=[[scott, EMP]])
  LogicalTableScan(table=[[scott, DEPT]])
{code}

  was:
We generate correlated join when no correlate variable is present on the right side.  However, this could be simplified to emit a normal join.

Given:
{code:java}
    final RelNode rel = builder
        .scan("EMP")
        .variable(v)
        .scan("DEPT")
        .join(JoinRelType.LEFT,
            builder.equals(builder.field(2, 0, "SAL"),
                builder.literal(1000)),
            ImmutableSet.of(v.get().id))
        .build();
{code}
Currently the following is emitted:
{code}
LogicalFilter(condition=[=($7, $8)])
  LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{0}])
    LogicalTableScan(table=[[scott, EMP]])
    LogicalFilter(condition=[=($cor0.DEPTNO, $0)])
      LogicalTableScan(table=[[scott, DEPT]])
{code}
After the changes the following will be emitted:
{code}
LogicalJoin(condition=[=($7, $8)], joinType=[left])
  LogicalTableScan(table=[[scott, EMP]])
  LogicalTableScan(table=[[scott, DEPT]])
{code}


> RelBuilder.join should only emit a correlate when a correlate variable exists
> -----------------------------------------------------------------------------
>
>                 Key: CALCITE-4668
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4668
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>            Reporter: James Starr
>            Priority: Major
>
> We generate correlated join when no correlate variable is present on the right side.  However, this could be simplified to emit a normal join.
> Given:
> {code:java}
> final RelNode rel = builder
>         .scan("EMP")
>         .variable(v)
>         .scan("DEPT")
>         .join(JoinRelType.LEFT,
>             builder.equals(builder.field(2, 0, "SAL"),
>                 builder.literal(1000)),
>             ImmutableSet.of(v.get().id))
>         .build();
> {code}
> Currently the following is emitted:
> {code}
> LogicalFilter(condition=[=($7, $8)])
>   LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{0}])
>     LogicalTableScan(table=[[scott, EMP]])
>     LogicalFilter(condition=[=($cor0.DEPTNO, $0)])
>       LogicalTableScan(table=[[scott, DEPT]])
> {code}
> After the changes the following will be emitted:
> {code}
> LogicalJoin(condition=[=($7, $8)], joinType=[left])
>   LogicalTableScan(table=[[scott, EMP]])
>   LogicalTableScan(table=[[scott, DEPT]])
> {code}



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