@VisibleForTesting
  public void runMapJoinCacheReuseOptimization(
      ParseContext pctx, SharedWorkOptimizerCache optimizerCache) throws SemanticException {
    // First we group together all the mapjoin operators whose first broadcast input is the same.
    final Multimap<Operator<?>, MapJoinOperator> parentToMapJoinOperators = ArrayListMultimap.create();
    for (Set<Operator<?>> workOperators : optimizerCache.getWorkGroups()) {
      for (Operator<?> op : workOperators) {
        if (op instanceof MapJoinOperator) {
          MapJoinOperator mapJoinOp = (MapJoinOperator) op;
          // Only allowed for mapjoin operator
          if (!mapJoinOp.getConf().isBucketMapJoin() &&
              !mapJoinOp.getConf().isDynamicPartitionHashJoin()) {
            parentToMapJoinOperators.put(
                obtainFirstBroadcastInput(mapJoinOp).getParentOperators().get(0), mapJoinOp);
          }
        }
      }
    }

    // For each group, set the cache key accordingly if there is more than one operator
    // and input RS operator are equal
    for (Collection<MapJoinOperator> c : parentToMapJoinOperators.asMap().values()) {
      Map<MapJoinOperator, String> mapJoinOpToCacheKey = new HashMap<>();
      for (MapJoinOperator mapJoinOp : c) {
        String cacheKey = null;
        for (Entry<MapJoinOperator, String> e: mapJoinOpToCacheKey.entrySet()) {
          if (canShareBroadcastInputs(pctx, mapJoinOp, e.getKey())) {
            cacheKey = e.getValue();
            break;
          }
        }

        if (cacheKey == null) {
          // Either it is the first map join operator or there was no equivalent broadcast input,
          // hence generate cache key
          cacheKey = MapJoinDesc.generateCacheKey(mapJoinOp.getOperatorId());
          mapJoinOpToCacheKey.put(mapJoinOp, cacheKey);
        }

        mapJoinOp.getConf().setCacheKey(cacheKey);
      }
    }
  }
Try to reuse cache for broadcast side in mapjoin operators that share the same input.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/SharedWorkOptimizer.java