private RelNode applyJoinOrderingTransform(RelNode basePlan, RelMetadataProvider mdProvider, RexExecutor executorProvider) {

      final HepProgramBuilder program = new HepProgramBuilder();
      // Remove Projects between Joins so that JoinToMultiJoinRule can merge them to MultiJoin.
      // If FK-PK are declared, it tries to pull non-filtering column appending join nodes.
      List<RelOptRule> rules = Lists.newArrayList();
      if (profilesCBO.contains(ExtendedCBOProfile.REFERENTIAL_CONSTRAINTS)) {
        rules.add(HiveJoinSwapConstraintsRule.INSTANCE);
      }
      rules.add(HiveSemiJoinProjectTransposeRule.INSTANCE);
      rules.add(HiveJoinProjectTransposeRule.LEFT_PROJECT_BTW_JOIN);
      rules.add(HiveJoinProjectTransposeRule.RIGHT_PROJECT_BTW_JOIN);
      rules.add(HiveProjectMergeRule.INSTANCE);
      if (profilesCBO.contains(ExtendedCBOProfile.REFERENTIAL_CONSTRAINTS)) {
        rules.add(conf.getBoolVar(HiveConf.ConfVars.HIVE_OPT_PPD_WINDOWING) ?
            HiveFilterProjectTransposeRule.DETERMINISTIC_WINDOWING_ON_NON_FILTERING_JOIN :
            HiveFilterProjectTransposeRule.DETERMINISTIC_ON_NON_FILTERING_JOIN);
        rules.add(HiveFilterJoinRule.FILTER_ON_NON_FILTERING_JOIN);
      }
      generatePartialProgram(program, true, HepMatchOrder.BOTTOM_UP,
          rules.toArray(new RelOptRule[0]));
      // Join reordering
      generatePartialProgram(program, false, HepMatchOrder.BOTTOM_UP,
          new JoinToMultiJoinRule(HiveJoin.class), HiveLoptOptimizeJoinRule.INSTANCE);

      RelNode calciteOptimizedPlan;
      try {
        calciteOptimizedPlan = executeProgram(basePlan, program.build(), mdProvider, executorProvider);
      } catch (Exception e) {
        if (noColsMissingStats.get() > 0) {
          LOG.warn("Missing column stats (see previous messages), skipping join reordering in CBO");
          noColsMissingStats.set(0);
          calciteOptimizedPlan = basePlan;
          disableSemJoinReordering = false;
        } else {
          throw e;
        }
      }

      return calciteOptimizedPlan;
    }
Perform join reordering optimization.

@param basePlan
         original plan
@param mdProvider
         meta data provider
@param executorProvider
         executor
@return
ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java