[
https://issues.apache.org/jira/browse/CALCITE-2883?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16781806#comment-16781806
]
Jesus Camacho Rodriguez commented on CALCITE-2883:
--------------------------------------------------
[~zabetak], thanks. I believe the javadoc refers mainly to {{addSubprogram}} vs
{{addRuleInstance}} behavior. However, it is true what you mention, that I had
not realized:
{code}
... When added as a subprogram, the sequence will execute repeatedly until a
fixpoint is reached, ...
{code}
However, since the subprogram has its own state for order and limit as
described above, I am still confused by the need of the loop and check in
{{HepPlanner}} subprogram execution method. Also, a subprogram could contain a
block of rules added using {{addRuleCollection}}, with its own match order and
limit definitions, hence I am not sure why a subprogram should enforce that
none of its rules has produced a new transformation, since this could be
enforced at that level (or maybe I am missing anything?).
[~kgyrtkirk], adding a parameter to a subprogram is an option indeed... But I
am still wondering if that loop is actually needed at all, or it was there just
because planner used to work differently before and it was not removed. If it
turns out to be useful, we can go with this option indeed.
[~julianhyde], [~perid007], you also modified the planner in the past. Do you
have any feedback?
> HepPlanner subprogram may loop till getting out of memory
> ---------------------------------------------------------
>
> Key: CALCITE-2883
> URL: https://issues.apache.org/jira/browse/CALCITE-2883
> Project: Calcite
> Issue Type: Bug
> Reporter: Jesus Camacho Rodriguez
> Assignee: Jesus Camacho Rodriguez
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.19.0
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> Consider the following two hep programs.
> Program 1:
> {code}
> final HepProgramBuilder programBuilder = new HepProgramBuilder();
> programBuilder.addMatchOrder(HepMatchOrder.BOTTOM_UP);
> programBuilder.addRuleInstance(JoinToMultiJoinRule.INSTANCE);
> programBuilder.addRuleInstance(LoptOptimizeJoinRule.INSTANCE);
> final HepProgram program = programBuilder.build();
> {code}
> Program 2:
> {code}
> final HepProgramBuilder programBuilder = new HepProgramBuilder();
> final HepProgramBuilder subprogramBuilder = new HepProgramBuilder();
> subprogramBuilder.addMatchOrder(HepMatchOrder.BOTTOM_UP);
> subprogramBuilder.addRuleInstance(JoinToMultiJoinRule.INSTANCE);
> subprogramBuilder.addRuleInstance(LoptOptimizeJoinRule.INSTANCE);
> programBuilder.addSubprogram(subprogramBuilder.build());
> final HepProgram program = programBuilder.build();
> {code}
> I would expect both programs to behave similarly. However, program 2 will
> loop indefinitely. The reason is that {{HepPlanner}} subprogram execution
> loops if subprogram generates any new expression.
> https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/plan/hep/HepPlanner.java#L339
> This does not seem right since planner can control exiting the program (and
> thus, subprogram) depending on its own internal state and configuration
> properties, e.g., match limit.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)