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

Moritz Mack commented on CALCITE-5503:
--------------------------------------

Thanks [~julianhyde] !

I'll rephrase the commit message (y)

I also looked into the Quidem tests, unfortunately I don't see a way to verify 
the improved plan. E.g.
{code:java}
!use scott

select * from emp where deptno = 10 and job = 'CLERK'
union all
select * from emp where deptno = 10 and job = 'CLERK';
+-------+--------+-------+------+------------+---------+------+--------+
| EMPNO | ENAME  | JOB   | MGR  | HIREDATE   | SAL     | COMM | DEPTNO |
+-------+--------+-------+------+------------+---------+------+--------+
|  7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 |      |     10 |
|  7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 |      |     10 |
+-------+--------+-------+------+------------+---------+------+--------+
(2 rows)

!ok
EnumerableUnion(all=[true])
  EnumerableCalc(expr#0..7=[{inputs}], expr#8=[CAST($t7):INTEGER], expr#9=[10], 
expr#10=[=($t8, $t9)], expr#11=['CLERK':VARCHAR(9)], expr#12=[=($t2, $t11)], 
expr#13=[AND($t10, $t12)], proj#0..7=[{exprs}], $condition=[$t13])
    EnumerableTableScan(table=[[scott, EMP]])
  EnumerableCalc(expr#0..7=[{inputs}], expr#8=[CAST($t7):INTEGER], expr#9=[10], 
expr#10=[=($t8, $t9)], expr#11=['CLERK':VARCHAR(9)], expr#12=[=($t2, $t11)], 
expr#13=[AND($t10, $t12)], proj#0..7=[{exprs}], $condition=[$t13])
    EnumerableTableScan(table=[[scott, EMP]])
!plan {code}
As far as I can see I cannot observe / verify identity on nodes of the printed 
plan. This is probably possible in the .dot representation, but not sure 
there's a decent way to use that in the Quidem tests.

What do you think?

 

> Memoize visited nodes in CheapestPlanReplacer
> ---------------------------------------------
>
>                 Key: CALCITE-5503
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5503
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>            Reporter: Moritz Mack
>            Assignee: Moritz Mack
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> When using CheapestPlanReplacer, semantics of a RelNode tree change if it 
> contains the same node multiple times in case this node has inputs itself 
> that have to be replaced. During replacement such nodes get copied on each 
> occurrence.
> Instead CheapestPlanReplacer should memoize previously visited nodes and emit 
> the same result again in the that case.
> The test case below illustrates the issue and fails on the current main 
> branch.
>  
> {code:java}
> @Test void testMemoizeInputRelNodes() {
>   VolcanoPlanner planner = new VolcanoPlanner();
>   planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
>   RelOptCluster cluster = newCluster(planner);
>   // The rule that triggers the assert rule
>   planner.addRule(PhysLeafRule.INSTANCE);
>   planner.addRule(GoodSingleRule.INSTANCE);
>   // Leaf RelNode
>   NoneLeafRel leafRel = new NoneLeafRel(cluster, "a");
>   RelNode leafPhy = planner
>       .changeTraits(leafRel, cluster.traitSetOf(PHYS_CALLING_CONVENTION));
>   // RelNode with leaf RelNode as single input
>   NoneSingleRel singleRel = new NoneSingleRel(cluster, leafPhy);
>   RelNode singlePhy = planner
>       .changeTraits(singleRel, cluster.traitSetOf(PHYS_CALLING_CONVENTION));
>   // Binary RelNode with identical input on either side
>   PhysBiRel parent = new PhysBiRel(
>       cluster, cluster.traitSetOf(PHYS_CALLING_CONVENTION), singlePhy, 
> singlePhy);
>   planner.setRoot(parent);
>   RelNode result = planner.chooseDelegate().findBestExp();
>   // Expect inputs to remain identical
>   assertEquals(result.getInput(0), result.getInput(1));
> } {code}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to