private static void setNewTag(IntraQueryCorrelation correlation,
      List<Operator<? extends OperatorDesc>> childrenOfDemux,
      ReduceSinkOperator rsop, Map<ReduceSinkOperator, Integer> bottomRSToNewTag)
          throws SemanticException {
    int newTag = bottomRSToNewTag.get(rsop);
    int oldTag = rsop.getConf().getTag();
    if (oldTag == -1) {
      // if this child of DemuxOperator does not use tag, we just set the oldTag to 0.
      oldTag = 0;
    }
    Operator<? extends OperatorDesc> child = CorrelationUtilities.getSingleChild(rsop, true);
    if (!childrenOfDemux.contains(child)) {
      childrenOfDemux.add(child);
    }
    int childIndex = childrenOfDemux.indexOf(child);
    correlation.setNewTag(newTag, oldTag, childIndex);
    rsop.getConf().setTag(newTag);
  }
QueryPlanTreeTransformation contains static methods used to transform
the query plan tree (operator tree) based on the correlation we have
detected by Correlation Optimizer.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/correlation/QueryPlanTreeTransformation.java