private static SharedResult createSharedResultForRoot(
      SharedWorkOptimizerCache optimizerCache,
      Operator<?> retainableOp,
      Operator<?> discardableOp,
      LinkedHashSet<Operator<?>> retainableOps,
      LinkedHashSet<Operator<?>> discardableOps,
      Set<Operator<?>> discardableInputOps) {
    // Assertion: retainableOps and discardableOps do not contain MapJoinOperator.

    // Accumulate InMemoryDataSize of unmerged MapJoin operators.
    long dataSize = 0L;
    long maxDataSize = 0L;

    Set<Operator<?>> opsWork1 = findWorkOperators(optimizerCache, retainableOp);
    for (Operator<?> op : opsWork1) {
      if (op instanceof MapJoinOperator) {
        MapJoinOperator mop = (MapJoinOperator) op;
        dataSize = StatsUtils.safeAdd(dataSize, mop.getConf().getInMemoryDataSize());
        if (maxDataSize < mop.getConf().getMemoryMonitorInfo().getAdjustedNoConditionalTaskSize()) {
          maxDataSize = mop.getConf().getMemoryMonitorInfo().getAdjustedNoConditionalTaskSize();
        }
      }
    }
    Set<Operator<?>> opsWork2 = findWorkOperators(optimizerCache, discardableOp);
    for (Operator<?> op : opsWork2) {
      if (op instanceof MapJoinOperator) {
        MapJoinOperator mop = (MapJoinOperator) op;
        dataSize = StatsUtils.safeAdd(dataSize, mop.getConf().getInMemoryDataSize());
        if (maxDataSize < mop.getConf().getMemoryMonitorInfo().getAdjustedNoConditionalTaskSize()) {
          maxDataSize = mop.getConf().getMemoryMonitorInfo().getAdjustedNoConditionalTaskSize();
        }
      }
    }

    return new SharedResult(retainableOps, discardableOps, discardableInputOps, dataSize, maxDataSize);
  }
Orders TS operators in decreasing order by "weight".
ql/src/java/org/apache/hadoop/hive/ql/optimizer/SharedWorkOptimizer.java