[
https://issues.apache.org/jira/browse/CALCITE-3977?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17104543#comment-17104543
]
Ruben Q L commented on CALCITE-3977:
------------------------------------
There is clearly something wrong with the Decorrelator and the field accesses.
If I try a simple correlate on author birthplace, everything goes fine:
{code}
b.scan("bookstore", "authors");
b.variable(cor0);
b.scan("bookstore", "authors");
b.filter(b.equals(
b.field("birthPlace"),
b.field(cor0.get(), "birthPlace")));
b.correlate(
JoinRelType.INNER,
cor0.get().id,
b.field(2, 0, "birthPlace"));
// ------------------------
before decorrelate
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{2}])
LogicalTableScan(table=[[bookstore, authors]])
LogicalFilter(condition=[=($2, $cor0.birthPlace)])
LogicalTableScan(table=[[bookstore, authors]])
after decorrelate
LogicalJoin(condition=[=($2, $6)], joinType=[inner])
LogicalTableScan(table=[[bookstore, authors]])
LogicalTableScan(table=[[bookstore, authors]])
{code}
However, the same plan, but correlating on author birthplace.city, looks
completely wrong (too many joins, correlated variable still in the plan):
{code}
b.scan("bookstore", "authors");
b.variable(cor0);
b.scan("bookstore", "authors");
b.filter(b.equals(
b.field(b.field("birthPlace"), "city"),
b.field(b.field(cor0.get(), "birthPlace"), "city")));
b.correlate(
JoinRelType.INNER,
cor0.get().id,
b.field(b.field(2, 0, "birthPlace"), "city"));
// ------------------------
before decorrelate
LogicalCorrelate(correlation=[$cor0], joinType=[inner], requiredColumns=[{4}])
LogicalProject(aid=[$0], name=[$1], birthPlace=[$2], books=[$3],
$f4=[$2.city])
LogicalTableScan(table=[[bookstore, authors]])
LogicalFilter(condition=[=($2.city, $cor0.birthPlace.city)])
LogicalTableScan(table=[[bookstore, authors]])
after decorrelate
LogicalJoin(condition=[=($2, $9)], joinType=[inner])
LogicalProject(aid=[$0], name=[$1], birthPlace=[$2], books=[$3],
$f4=[$2.city])
LogicalTableScan(table=[[bookstore, authors]])
LogicalJoin(condition=[true], joinType=[inner])
LogicalFilter(condition=[=($2.city, $cor0.birthPlace.city)])
LogicalTableScan(table=[[bookstore, authors]])
LogicalAggregate(group=[{0}])
LogicalProject(birthPlace=[$2])
LogicalTableScan(table=[[bookstore, authors]])
{code}
> RelDecorrelator does not resolve correlation variable with field accesses
> -------------------------------------------------------------------------
>
> Key: CALCITE-3977
> URL: https://issues.apache.org/jira/browse/CALCITE-3977
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.22.0
> Reporter: Thomas Rebele
> Priority: Major
> Attachments: Calcite3977.java
>
>
> The RelCorrelator seems to have problems with some plans that contain a field
> access (probably a RexFieldAccess, but I haven't looked further into it). In
> this ticket there's a filter on *$cor0.birthPlace.city*.
> Here the complete plan:
> {code:java}
> before decorrelate
> LogicalCorrelate(correlation=[$cor0], joinType=[left], requiredColumns=[{}])
> LogicalTableScan(table=[[bookstore, authors]])
> LogicalFilter(condition=[=('Munich', $cor0.birthPlace.city)])
> LogicalTableScan(table=[[bookstore, authors]])
> after decorrelate
> LogicalJoin(condition=[=($2, $8)], joinType=[left])
> LogicalTableScan(table=[[bookstore, authors]])
> LogicalJoin(condition=[true], joinType=[inner])
> LogicalFilter(condition=[=('Munich', $cor0.birthPlace.city)])
> LogicalTableScan(table=[[bookstore, authors]])
> LogicalAggregate(group=[{0}])
> LogicalProject(birthPlace=[$2])
> LogicalTableScan(table=[[bookstore, authors]])
> {code}
> There seem to be two problems:
> * The LogicalCorrelate has been removed, but the $cor0.birthPlace.city is
> still in the filter condition.
> * The inner join does not seem to be necessary. If it is, could somebody
> explain, why?
--
This message was sent by Atlassian Jira
(v8.3.4#803005)