This is an automated email from the ASF dual-hosted git repository.

huajianlan pushed a commit to branch fe_local_shuffle
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/fe_local_shuffle by this push:
     new 2fdef106fa4 [fix](local shuffle) fix computeDestIdToInstanceId picking 
wrong ExchangeNode for multi-input fragments
2fdef106fa4 is described below

commit 2fdef106fa44b0b1dde516a86734044652faee4c
Author: 924060929 <[email protected]>
AuthorDate: Tue Mar 31 16:52:57 2026 +0800

    [fix](local shuffle) fix computeDestIdToInstanceId picking wrong 
ExchangeNode for multi-input fragments
    
    When a fragment has multiple ExchangeNode inputs (e.g., NLJ with probe side 
+ BROADCAST
    build side), computeDestIdToInstanceId was using .iterator().next() which 
could arbitrarily
    pick the BROADCAST input. A BROADCAST ExchangeNode has only 1 destination 
per BE, so
    shuffle_idx_to_instance_idx would have only 1 entry instead of the expected 
N (ppt per BE).
    This caused GLOBAL_HASH LOCAL_EXCHANGE to lose rows with 'Rows mismatched' 
error because
    most hash partition indices were absent from the map.
    
    Fix: iterate all inputs and select the one with the most destinations on 
this worker,
    which correctly identifies the main data-carrying ExchangeNode.
---
 .../doris/qe/runtime/ThriftPlansBuilder.java       | 28 +++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/qe/runtime/ThriftPlansBuilder.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/runtime/ThriftPlansBuilder.java
index 2dfafd2ff6b..39f49dbedfd 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/qe/runtime/ThriftPlansBuilder.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/qe/runtime/ThriftPlansBuilder.java
@@ -572,7 +572,33 @@ public class ThriftPlansBuilder {
         // but only the first one actually receives remote data. In that case 
receiverPlan.getInstanceJobs()
         // no longer matches sender destinations, and using receiver instance 
order will produce an invalid
         // shuffle_idx_to_instance_idx mapping for BE.
-        Entry<ExchangeNode, DistributedPlan> exchangeToChildPlan = 
receivePlan.getInputs().entries().iterator().next();
+        //
+        // When a fragment has multiple ExchangeNode inputs (e.g., NLJ with 
probe + BROADCAST build sides),
+        // always pick the one with the most destinations on this worker. A 
BROADCAST input has 1 dest per BE
+        // while the main data-carrying input (HASH-partitioned probe) has N 
dests per BE; using the BROADCAST
+        // one would produce a 1-entry map for GLOBAL_HASH LOCAL_EXCHANGE, 
causing rows to be lost.
+        Entry<ExchangeNode, DistributedPlan> exchangeToChildPlan = null;
+        int maxDestsOnWorker = -1;
+        for (Entry<ExchangeNode, DistributedPlan> entry : 
receivePlan.getInputs().entries()) {
+            ExchangeNode exchNode = entry.getKey();
+            PipelineDistributedPlan childPlan = (PipelineDistributedPlan) 
entry.getValue();
+            for (Entry<DataSink, List<AssignedJob>> kv : 
childPlan.getDestinations().entrySet()) {
+                if (kv.getKey().getExchNodeId().asInt() != 
exchNode.getId().asInt()) {
+                    continue;
+                }
+                int destsOnWorker = (int) kv.getValue().stream()
+                        .filter(j -> j.getAssignedWorker().id() == worker.id())
+                        .count();
+                if (destsOnWorker > maxDestsOnWorker) {
+                    maxDestsOnWorker = destsOnWorker;
+                    exchangeToChildPlan = entry;
+                }
+                break;
+            }
+        }
+        if (exchangeToChildPlan == null) {
+            return destIdToInstanceId;
+        }
         ExchangeNode linkNode = exchangeToChildPlan.getKey();
         PipelineDistributedPlan firstInputPlan = (PipelineDistributedPlan) 
exchangeToChildPlan.getValue();
         for (Entry<DataSink, List<AssignedJob>> kv : 
firstInputPlan.getDestinations().entrySet()) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to