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 e6f9a2526bb [fix](fe) Fix BUCKET_SHUFFLE join wrong results with 
serial exchange
e6f9a2526bb is described below

commit e6f9a2526bb95a755c5ce91e47b3e43b7c67ec2e
Author: 924060929 <[email protected]>
AuthorDate: Wed Apr 8 22:12:57 2026 +0800

    [fix](fe) Fix BUCKET_SHUFFLE join wrong results with serial exchange
    
    ### What problem does this PR solve?
    
    Problem Summary: When use_serial_exchange=true and scan is serial 
(pptn*numBEs > buckets),
    BUCKET_SHUFFLE join build side used PASS_TO_ONE local exchange, which 
routes ALL build data
    to task 0. Unlike BROADCAST joins, BUCKET_SHUFFLE has no shared hash table 
mechanism, so
    tasks 1..N-1 build empty hash tables and lose rows.
    
    Fix:
    1. ExchangeNode: serial HASH/BUCKET exchanges return NOOP (not PASSTHROUGH) 
to let parent
       insert the correct redistribution. PASSTHROUGH round-robin corrupts 
hash/bucket distribution.
    2. HashJoinNode: BUCKET_SHUFFLE build side always uses requireBucketHash() 
instead of
       requirePassToOne(). Combined with the NOOP from ExchangeNode, 
enforceChildExchange()
       inserts PASSTHROUGH → BUCKET_HASH_SHUFFLE chain, correctly distributing 
data by bucket.
    
    ### Release note
    
    None
    
    ### Check List (For Author)
    
    - Test: Manual test on 3-BE cluster (all 12 pptn/serial/share combos pass)
    - Behavior changed: No
    - Does this need documentation: No
    
    Co-authored-by: Copilot <[email protected]>
---
 .../org/apache/doris/planner/ExchangeNode.java     | 17 +++++++++++++---
 .../org/apache/doris/planner/HashJoinNode.java     | 23 +++++++++-------------
 2 files changed, 23 insertions(+), 17 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/planner/ExchangeNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/ExchangeNode.java
index 59c89f701bb..60d42500d5e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/ExchangeNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/ExchangeNode.java
@@ -189,9 +189,20 @@ public class ExchangeNode extends PlanNode {
                 && fragment != null
                 && fragment.useSerialSource(ConnectContext.get());
         if (willBeSerialOnBe) {
-            // Serial exchange → 1 task. Insert PASSTHROUGH to fan out to N 
tasks.
-            // Parent nodes (HashJoin, etc.) may add PASS_TO_ONE on top if 
they need
-            // single-builder semantics (e.g., broadcast join build side).
+            // Serial exchange → 1 task. Must fan out to N tasks for 
downstream operators.
+            // For HASH/BUCKET exchanges: return NOOP and let parent insert 
the appropriate
+            // redistribution (HASH_SHUFFLE or BUCKET_HASH_SHUFFLE). 
PASSTHROUGH round-robin
+            // would corrupt the hash/bucket distribution, and PASS_TO_ONE 
doesn't work for
+            // BUCKET_SHUFFLE joins (no shared hash table mechanism unlike 
BROADCAST).
+            // The heavy-ops bottleneck avoidance in enforceChildExchange() 
will automatically
+            // insert a PASSTHROUGH fan-out before the hash/bucket shuffle if 
needed.
+            if (partitionType == TPartitionType.HASH_PARTITIONED
+                    || partitionType == 
TPartitionType.BUCKET_SHFFULE_HASH_PARTITIONED) {
+                return Pair.of(this, LocalExchangeType.NOOP);
+            }
+            // For UNPARTITIONED (broadcast): PASSTHROUGH fan-out is safe 
because the
+            // exchange has the complete dataset. Parent nodes (HashJoin) may 
add PASS_TO_ONE
+            // on top for single-builder semantics (broadcast join build side).
             PlanNode pt = new 
LocalExchangeNode(translatorContext.nextPlanNodeId(),
                     this, LocalExchangeType.PASSTHROUGH, null);
             return Pair.of(pt, LocalExchangeType.PASSTHROUGH);
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java
index 02d148ea5aa..c353463cb99 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/HashJoinNode.java
@@ -323,20 +323,15 @@ public class HashJoinNode extends JoinNodeBase {
             outputType = probeChildSerial ? LocalExchangeType.PASSTHROUGH : 
null;
         } else if (AddLocalExchange.isColocated(this) || isBucketShuffle()) {
             probeSideRequire = LocalExchangeTypeRequire.requireBucketHash();
-            if (isBucketShuffle() && isSerialChildInThrift(translatorContext, 
children.get(1))) {
-                // BUCKET_SHUFFLE only: build child is ExchangeNode from 
another fragment.
-                // When serial (pooling scan), the Exchange reduces the build 
pipeline's
-                // num_tasks to _parallel_instances=1 via add_operator(). This 
causes
-                // instance 1+ to have probe tasks without build tasks → 
shared state
-                // injection fails. Use requirePassToOne to insert a local 
exchange that
-                // restores num_tasks, matching BE-native's PASSTHROUGH 
insertion.
-                // NOT for COLOCATE: build child is ScanNode in same fragment, 
no Exchange,
-                // no serial num_tasks reduction. Using PASS_TO_ONE would 
incorrectly route
-                // all build data to 1 instance, losing rows.
-                buildSideRequire = LocalExchangeTypeRequire.requirePassToOne();
-            } else {
-                buildSideRequire = 
LocalExchangeTypeRequire.requireBucketHash();
-            }
+            // For BUCKET_SHUFFLE with serial build child: use 
requireBucketHash() (not
+            // requirePassToOne()). Unlike BROADCAST joins, BUCKET_SHUFFLE has 
no shared
+            // hash table mechanism — PASS_TO_ONE routes all data to task 0 
while tasks 1..N-1
+            // build empty hash tables, losing rows. BUCKET_HASH_SHUFFLE 
correctly distributes
+            // build data by bucket to match the probe side's bucket 
distribution.
+            // The serial exchange returns NOOP, so enforceChildExchange() 
will insert a
+            // BUCKET_HASH_SHUFFLE local exchange (with PASSTHROUGH fan-out 
for heavy-ops
+            // bottleneck avoidance).
+            buildSideRequire = LocalExchangeTypeRequire.requireBucketHash();
             outputType = AddLocalExchange.resolveExchangeType(
                     LocalExchangeTypeRequire.requireBucketHash(), 
translatorContext, this,
                     children.get(0));


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

Reply via email to