You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by "kasakrisz (via GitHub)" <gi...@apache.org> on 2026/09/21 12:59:39 UTC

[PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

kasakrisz opened a new pull request, #6806:
URL: https://github.com/apache/hive/pull/6806

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://cwiki.apache.org/confluence/display/Hive/HowToContribute
     2. Ensure that you have created an issue on the Hive project JIRA: https://issues.apache.org/jira/projects/HIVE/summary
     3. Ensure you have added or run the appropriate tests for your PR: 
     4. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP]HIVE-XXXXX:  Your PR title ...'.
     5. Be sure to keep the PR description updated to reflect all changes.
     6. Please write your PR title to summarize what this PR proposes.
     7. If possible, provide a concise example to reproduce the issue for a faster review.
   
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description, screenshot and/or a reproducible example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Hive versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   ### How was this patch tested?
   ```
   mvn test -Dtest.output.overwrite -Dtest=TestMiniLlapLocalCliDriver -Dqfile=sharedwork_dpp_no_map_join.q -pl itests/qtest -Pitests
    mvn test -Dtest=TestSharedWorkOptimizer -pl ql
   ```


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4083221567


##########
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:
   question is, would (M1 ∪ R2) and the PR (R2) lead to the same merge decisions?



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6806:
URL: https://github.com/apache/hive/pull/6806#issuecomment-5812494872

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6806) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [2 New issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6806&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6806&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6806&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6806&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6806&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6806)
   
   


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "kasakrisz (via GitHub)" <gi...@apache.org>.
kasakrisz commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4091890415


##########
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)) {

Review Comment:
   No, those should be excluded. Thanks for the explanation. Fixed.



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4082200911


##########
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)) {

Review Comment:
   should we reverse order - i.e `excludeOps.contains(op) || !visited.add(op)`



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4082358403


##########
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:
   SELECT * FROM t WHERE t.p = (SELECT max(p) FROM t);
   
   Map 1:      TS[t] -> SEL -> RS1          (RS1 feeds Reducer 2)
                     \-> FIL -> ...         (the outer query's branch)
   Reducer 2:  GBY(max p) -> SEL -> EVENT   (EVENT = DPP targeting TS[t] in Map 1)
   
   Edge back to the start work (M1 → R2 → DPP → M1)
   
   **M1 ∪ R2** vs new visitor approach: **R2**



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "kasakrisz (via GitHub)" <gi...@apache.org>.
kasakrisz commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4082381034


##########
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:
   I wanted to follow the pattern `findAscendantOperators` already has:
   `Set<Operator<?>> visited + Queue<Operator<?>> remaining`
   



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4082290371


##########
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:
   an alternative could be adding set.removeAll(result); before workOps = set;
   keeps the start work in the result when a semijoin/DPP back-edge reaches it



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4082290371


##########
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:
   an alternative could be adding set.removeAll(result); before workOps = set;



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #6806:
URL: https://github.com/apache/hive/pull/6806#issuecomment-5790292734

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6806) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [1 New issue](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6806&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_hive&pullRequest=6806&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_hive&pullRequest=6806&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6806&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_hive&pullRequest=6806&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_hive&pullRequest=6806)
   
   


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "kasakrisz (via GitHub)" <gi...@apache.org>.
kasakrisz commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4091538438


##########
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:
   > SELECT * FROM t WHERE t.p = (SELECT max(p) FROM t);
   
   Could you please share the context, DDL and sample data.



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "kasakrisz (via GitHub)" <gi...@apache.org>.
kasakrisz commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4091803977


##########
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:
   > Map 1: TS[t] -> SEL -> RS1 (RS1 feeds Reducer 2) -> FIL -> ... (the outer query's branch) Reducer 2: GBY(max p) -> SEL -> EVENT (EVENT = DPP targeting TS[t] in Map 1)
   > 
   > Edge back to the start work (M1 → R2 → DPP → M1)
   > 
   > **M1 ∪ R2** vs new visitor approach: **R2**
   
   > question is, would (M1 ∪ R2) and the PR (R2) lead to the same merge decisions?
   
   While I was debugging the original code using the query in `ql/src/test/queries/clientpositive/sharedwork_dpp_no_map_join.q` I observed that the starting work operators were never added to the result.



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4082200911


##########
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)) {

Review Comment:
   should we reverse order - i.e `excludeOps.contains(op) || !visited.add(op)`? excludeOps might be reported as descendants



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4082290371


##########
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:
   an alternative could be adding `set.removeAll(result);` before workOps = set;
   keeps the start work in the result when a semijoin/DPP back-edge reaches it



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "kasakrisz (via GitHub)" <gi...@apache.org>.
kasakrisz merged PR #6806:
URL: https://github.com/apache/hive/pull/6806


-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "kasakrisz (via GitHub)" <gi...@apache.org>.
kasakrisz commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4082366198


##########
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)) {

Review Comment:
   Could you please elaborate on why reversing the order is needed here?



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4083081645


##########
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)) {

Review Comment:
   excludeOps would be included into visited, is that ok ? 



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4083081645


##########
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)) {

Review Comment:
   excluded operators (excludeOps) are still reported (included into visited) but not traversed , is that ok ? 



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "deniskuzZ (via GitHub)" <gi...@apache.org>.
deniskuzZ commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4095736219


##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/SharedWorkOptimizer.java:
##########
@@ -2068,44 +2068,48 @@ 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 (excludeOps.contains(op)) {

Review Comment:
   i would collapse 2 block into 1, but either ok 
   ````
   if (excludeOps.contains(op) || !visited.add(op)) {
     continue;
   }
   ````



##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/SharedWorkOptimizer.java:
##########
@@ -2068,44 +2068,48 @@ 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 (excludeOps.contains(op)) {

Review Comment:
   i would collapse 2 blocks into 1, but either ok 
   ````
   if (excludeOps.contains(op) || !visited.add(op)) {
     continue;
   }
   ````



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org


Re: [PR] HIVE-30080: Queries can get stuck compiling during SharedWorkOptimizer [hive]

Posted by "kasakrisz (via GitHub)" <gi...@apache.org>.
kasakrisz commented on code in PR #6806:
URL: https://github.com/apache/hive/pull/6806#discussion_r4091538438


##########
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:
   > SELECT * FROM t WHERE t.p = (SELECT max(p) FROM t);
   
   Could you please share the context, DDL and sample data, settings.



-- 
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: gitbox-unsubscribe@hive.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org