private static void removeBranch(Operator<?> currentOp, Set<Operator<?>> branchesOps,
          Set<Operator<?>> discardableOps, SharedWorkOptimizerCache optimizerCache) {
    if (currentOp.getNumChild() > 1) {
      for (Operator<?> childOp : currentOp.getChildOperators()) {
        if (!branchesOps.contains(childOp) && !discardableOps.contains(childOp)) {
          return;
        }
      }
    }
    branchesOps.add(currentOp);
    if (currentOp.getParentOperators() != null && currentOp.getParentOperators().size() > 0) {
      for (Operator<?> parentOp : currentOp.getParentOperators()) {
        removeBranch(parentOp, branchesOps, discardableOps, optimizerCache);
      }
    } else if (currentOp instanceof TableScanOperator) {
      Collection<Operator<?>> c = optimizerCache.tableScanToDPPSource
              .get((TableScanOperator) currentOp);
      for (Operator<?> dppSource : c) {
        // Remove the branches
        removeBranch(dppSource, branchesOps, discardableOps, optimizerCache);
      }
    }
  }
Orders TS operators in decreasing order by "weight".
ql/src/java/org/apache/hadoop/hive/ql/optimizer/SharedWorkOptimizer.java