[
https://issues.apache.org/jira/browse/CALCITE-7340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149593#comment-18149593
]
zzwqqq commented on CALCITE-7340:
---------------------------------
For example, this query reads q twice. Only the second use is filtered.
{code:sql}
WITH q AS (
SELECT l.k, r.x
FROM (VALUES (1), (2)) AS l(k)
JOIN (VALUES (1), (2), (3)) AS r(x) ON r.x = l.k
)
SELECT * FROM q AS a
CROSS JOIN (SELECT * FROM q WHERE k > 1) AS b
{code}
I used HepPlanner to turn the join in q into a Correlate, then applied filter
pushdown.
{noformat}
Before pushdown
LogicalJoin
LogicalCorrelate($cor0)
LogicalFilter(K > 1)
LogicalCorrelate($cor0) (same object as the join's left input)
After pushdown
LogicalJoin
LogicalCorrelate($cor0, left input: all rows)
LogicalCorrelate($cor0, left input: K > 1)
{noformat}
The first use still needs all the rows, so the rule makes a copy for the
second. Correlate.copy keeps $cor0, leaving two declarations. I agree that the
copy’s declaration and all references bound by it should be renamed together.
If the copy fully replaces the original, it can keep the old id. Should
FilterCorrelateRule give the copy a new id when it creates it, or should the
planner assign one only if both Correlates remain in the plan?
> The rules governing the use of CorrelationId values in plans are not fully
> specified
> ------------------------------------------------------------------------------------
>
> Key: CALCITE-7340
> URL: https://issues.apache.org/jira/browse/CALCITE-7340
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.41.0
> Reporter: Mihai Budiu
> Priority: Minor
>
> This issue is really about the Calcite internal representation of Rel nodes.
> There have been several recent discussions about manipulating plans that
> contain CorrelationId values, and the conclusion seems to be that the rules
> governing the use of such variables is not clear.
> Ideally these rules should be spelled out in a specification, and there
> should be a tool to enforce them by validating plans. The JavaDoc for this
> tool may be the right place to write the specification. I don't expect that
> the specification will be long or complicated.
> RelBuilder may not be the right place to enforce such rules, because it
> usually does not have visibility over the entire plan, and some of these
> rules have to apply globally over entire plans.
> See CALCITE-5784, CALCITE-7045 and the discussion in github over CALCITE-7336
> for examples.
>
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)