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

Reduce loops to optimize RelSubset#getParents and RelSubset#getParentSubsets

    XMLWordPrintableJSON

Details

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

    Description

       

      /**
       * Returns the collection of RelNodes one of whose inputs is in this
       * subset.
       */
      Set<RelNode> getParents() {
        final Set<RelNode> list = new LinkedHashSet<>();
        for (RelNode parent : set.getParentRels()) {
          for (RelSubset rel : inputSubsets(parent)) {
            // see usage of this method in propagateCostImprovements0()
            if (rel == this) {
              list.add(parent);
              break;
            }
          }
        }
        return list;
      }
      
      /**
       * Returns the collection of distinct subsets that contain a RelNode one
       * of whose inputs is in this subset.
       */
      Set<RelSubset> getParentSubsets(VolcanoPlanner planner) {
        final Set<RelSubset> list = new LinkedHashSet<>();
        for (RelNode parent : set.getParentRels()) {
          for (RelSubset rel : inputSubsets(parent)) {
            if (rel.set == set && rel.getTraitSet().equals(traitSet)) {
              list.add(planner.getSubsetNonNull(parent));
              break;
            }
          }
        }
        return list;
      }

       

      Once we have found a matching Relsubset from its parent input, the subsequent inner loop is unnecessary,so we can immediately end the inner loop to save a little time. This is just a minor improment.

      Attachments

        Issue Links

          Activity

            People

              xinqiu asdfgh19
              xinqiu asdfgh19
              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
                  1h