deniskuzZ commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4095755379
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/SharedWorkOptimizer.java:
##########
@@ -2068,44 +2068,43 @@ private static Set<Operator<?>>
findAscendantOperators(SharedWorkOptimizerCache
return visited;
}
- private static Set<Operator<?>> findDescendantWorkOperators(ParseContext
pctx,
+ @VisibleForTesting
+ static Set<Operator<?>> findDescendantWorkOperators(ParseContext pctx,
SharedWorkOptimizerCache optimizerCache, Operator<?> start,
Set<Operator<?>> excludeOps) {
- // Find operators in work
- Set<Operator<?>> workOps = findWorkOperators(optimizerCache, start);
- // Gather output works operators
- Set<Operator<?>> result = new HashSet<Operator<?>>();
- Set<Operator<?>> set;
- while (!workOps.isEmpty()) {
- set = new HashSet<Operator<?>>();
- for (Operator<?> op : workOps) {
- if (excludeOps.contains(op)) {
- continue;
- }
- if (op instanceof ReduceSinkOperator) {
- if (op.getChildOperators() != null) {
- // All children of RS are descendants
- for (Operator<?> child : op.getChildOperators()) {
- set.addAll(findWorkOperators(optimizerCache, child));
- }
- }
- // Semijoin DPP work is considered a descendant because work needs
- // to finish for it to execute
- SemiJoinBranchInfo sjbi = pctx.getRsToSemiJoinBranchInfo().get(op);
- if (sjbi != null) {
- set.addAll(findWorkOperators(optimizerCache, sjbi.getTsOp()));
+
+ // Gather input operators
+ Set<Operator<?>> startWorkOperators = findWorkOperators(optimizerCache,
start);
+ Set<Operator<?>> visited = new HashSet<>();
+ Queue<Operator<?>> remaining = new LinkedList<>(startWorkOperators);
+ while (!remaining.isEmpty()) {
+ Operator<?> op = remaining.poll();
+ if (!visited.add(op) || excludeOps.contains(op)) {
+ continue;
+ }
+
+ if (op instanceof ReduceSinkOperator) {
+ if (op.getChildOperators() != null) {
+ // All children of RS are descendants
+ for (Operator<?> child : op.getChildOperators()) {
+ remaining.addAll(findWorkOperators(optimizerCache, child));
}
- } else if(op.getConf() instanceof DynamicPruningEventDesc) {
- // DPP work is considered a descendant because work needs
- // to finish for it to execute
- set.addAll(findWorkOperators(
- optimizerCache, ((DynamicPruningEventDesc)
op.getConf()).getTableScan()));
}
+ // Semijoin DPP work is considered a descendant because work needs
+ // to finish for it to execute
+ SemiJoinBranchInfo sjbi = pctx.getRsToSemiJoinBranchInfo().get(op);
+ if (sjbi != null) {
+ remaining.addAll(findWorkOperators(optimizerCache, sjbi.getTsOp()));
+ }
+ } else if (op.getConf() instanceof DynamicPruningEventDesc) {
+ // DPP work is considered a descendant because work needs
+ // to finish for it to execute
+ remaining.addAll(findWorkOperators(optimizerCache,
((DynamicPruningEventDesc) op.getConf()).getTableScan()));
}
- workOps = set;
Review Comment:
Ran an instrumented build computing both variants side by side (visited-set
traversal from this PR vs the legacy loop + set.removeAll(result)), logging
whenever the descendant sets or the validPreConditions check-2 decision differ.
Across the 12 sharedwork*.q qtests (incl. sharedwork_dpp_no_map_join.q) and
all 200 TestTezTPCDS30TBPerfCliDriver tests: 817 check-2 evaluations, 0 cases
where a back-edge reaches the start work, 0 descendant-set differences, 0
decision flips. So M1 ∪ R2 vs R2 doesn't arise in practice
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]