[
https://issues.apache.org/jira/browse/CALCITE-2883?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16781566#comment-16781566
]
Stamatis Zampetakis commented on CALCITE-2883:
----------------------------------------------
I don't think they should behave the same. The public API for adding a
SubProgram ((HepProgramBuilder.addSubprogram) defines the following:
{code:java}
/**
* Adds an instruction to execute a subprogram. Note that this is different
* from adding the instructions from the subprogram individually. When added
* as a subprogram, the sequence will execute repeatedly until a fixpoint is
* reached, whereas when the instructions are added individually, the
* sequence will only execute once (with a separate fixpoint for each
* instruction).
*
* <p>The subprogram has its own state for match order and limit
* (initialized to the defaults every time the subprogram is executed) and
* any changes it makes to those settings do not affect the parent program.
*
* @param program subprogram to execute
*/
{code}
> 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)