Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-5503

CheapestPlanReplacer should reuse repeated nodes in a DAG plan

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 1.34.0
    • core

    Description

      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.

       

      @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));
      } 

       

      Attachments

        Issue Links

          Activity

            People

              mosche Moritz Mack
              mosche Moritz Mack
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 10m
                  1h 10m