[ 
https://issues.apache.org/jira/browse/CALCITE-7340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149311#comment-18149311
 ] 

zzwqqq commented on CALCITE-7340:
---------------------------------

I agree with [~mbudiu]  that we should define valid plans first. In a complete 
plan, I’d require each independent binding to have its own id. Every reference 
must have a visible definition. For example, if a Correlate binds $cor0, then 
$cor0.K in its right input reads K from the current left row.

My prototype adds a helper, CorrelationBindings. I first tried it in 
SubQueryRemoveRule. The rule tells it which bindings are still in use. A 
replacement can keep the old id. For an independent copy, the helper calls 
RelOptCluster.createCorrel() and updates the references bound by that copy. In 
[~dongsl]  COUNT/SUM example, each right input referenced its own Correlate 
after expansion. The plan passed validation.

I’m unsure when to assign a new id if two inputs share the same Correlate 
instance. Rewriting one use can leave both the original and a copy. Should we 
assign the copy a new id when we attach it to 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)

Reply via email to