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

commit 0f7acce7308fe4776c49d16e16b7004e113f06d5
Author: 924060929 <[email protected]>
AuthorDate: Sun Apr 12 01:04:42 2026 +0800

    [fix](local shuffle) Fix COREDUMP/data-loss: skip LE for serial non-Scan 
children in insertLocalExchange
    
    In insertLocalExchange(), skip LE insertion when child is a serial
    non-ScanNode operator (Exchange, AGG, etc.) and the exchange type is
    not BROADCAST/PASS_TO_ONE. This mirrors BE need_to_local_exchange which
    skips LE when serial operators are in the pipeline.
    
    Without this guard, inserting PASSTHROUGH/ADAPTIVE_PASSTHROUGH between
    serial operators creates pipeline splits that:
    - Break AggSink↔AggSource shared state → DCHECK/SIGSEGV (source_deps empty)
    - Route 1-task output to 1/N downstream tasks → data loss (wrong COUNT 
DISTINCT)
    
    BROADCAST and PASS_TO_ONE are exempted: they replicate/route data
    correctly even with serial upstream (1→N or 1→1).
    
    Serial ScanNodes (pooling scan) still get LE fan-out via the heavy-ops
    path below the guard.
    
    Revert AGG-specific ScanNode/ExchangeNode checks — the guard in
    insertLocalExchange is the unified fix point for all operator types.
    
    Reproducer: multi-distinct COUNT/MIN on 56-bucket table with
    pptn=4/6, use_serial_exchange=true/false.
---
 .../org/apache/doris/planner/AggregationNode.java  | 18 +-----
 .../java/org/apache/doris/planner/PlanNode.java    | 12 ++++
 .../test_local_shuffle_rqg_bugs.groovy             | 72 ++++++++++++++++++++++
 3 files changed, 87 insertions(+), 15 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java
index 386d86b4b3f..65d9792c807 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java
@@ -285,13 +285,7 @@ public class AggregationNode extends PlanNode {
                 } else {
                     requireChild = parentRequire.autoRequireHash();
                 }
-            } else if 
(sessionVariable.enableDistinctStreamingAggForcePassthrough
-                    && children.get(0) instanceof ScanNode) {
-                // Only request PASSTHROUGH when child is a ScanNode (pooling 
scan fan-out).
-                // For any other serial child (Exchange, AGG, etc.), inserting 
PASSTHROUGH
-                // creates a pipeline split that breaks AggSink↔AggSource 
shared state
-                // → DCHECK/SIGSEGV in set_ready_to_read(). In BE, 
need_to_local_exchange
-                // sees serial operators in the pipeline and skips LE 
insertion.
+            } else if 
(sessionVariable.enableDistinctStreamingAggForcePassthrough) {
                 requireChild = LocalExchangeTypeRequire.requirePassthrough();
             } else {
                 requireChild = LocalExchangeTypeRequire.noRequire();
@@ -304,13 +298,9 @@ public class AggregationNode extends PlanNode {
                     && 
sessionVariable.enableStreamingAggHashJoinForcePassthrough) {
                 requireChild = LocalExchangeTypeRequire.requirePassthrough();
             } else if (fragment != null && 
fragment.useSerialSource(connectContext)
-                    && children.get(0).isSerialOperator()
-                    && children.get(0) instanceof ScanNode) {
+                    && children.get(0).isSerialOperator()) {
                 // Mirrors BE 
StreamingAggOperatorX::required_data_distribution():
                 //   return _child->is_serial_operator() ? PASSTHROUGH : NOOP
-                // Only request PASSTHROUGH for serial ScanNode children 
(pooling scan).
-                // For other serial children (Exchange, AGG), inserting 
PASSTHROUGH creates
-                // a pipeline split that breaks AggSink↔AggSource shared state 
pairing.
                 requireChild = LocalExchangeTypeRequire.requirePassthrough();
             } else {
                 requireChild = LocalExchangeTypeRequire.noRequire();
@@ -323,9 +313,7 @@ public class AggregationNode extends PlanNode {
                     requireChild = LocalExchangeTypeRequire.noRequire();
                 } else {
                     // Serialize agg, no group key: base class → child serial 
→ PASSTHROUGH, else NOOP
-                    // Only for ScanNode children (pooling scan) — same reason 
as above.
-                    if (fragment != null && 
fragment.useSerialSource(connectContext)
-                            && children.get(0) instanceof ScanNode) {
+                    if (fragment != null && 
fragment.useSerialSource(connectContext)) {
                         requireChild = 
LocalExchangeTypeRequire.requirePassthrough();
                     } else {
                         requireChild = LocalExchangeTypeRequire.noRequire();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java
index cad9745c9eb..018b83d8a4a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/PlanNode.java
@@ -1063,6 +1063,18 @@ public abstract class PlanNode extends 
TreeNode<PlanNode> {
      */
     private PlanNode insertLocalExchange(PlanTranslatorContext 
translatorContext,
             PlanNode child, LocalExchangeType exchangeType, List<Expr> 
distributeExprs) {
+        // Mirrors BE need_to_local_exchange: skip 
PASSTHROUGH/ADAPTIVE_PASSTHROUGH LE when
+        // child is a serial non-Scan operator. Serial Exchanges/AGGs have 1 
task; inserting
+        // PASSTHROUGH/APT creates a pipeline split that breaks shared state 
(COREDUMP) or
+        // causes data loss (routes 1-task output to only 1 of N downstream 
tasks).
+        // HASH/BUCKET/BROADCAST/PASS_TO_ONE are NOT skipped — they properly 
redistribute
+        // or replicate data and are needed even with serial upstream.
+        // Serial ScanNodes (pooling scan) need fan-out and are handled by the 
heavy-ops path below.
+        if (child.isSerialOperator() && !(child instanceof ScanNode)
+                && (exchangeType == LocalExchangeType.PASSTHROUGH
+                    || exchangeType == 
LocalExchangeType.ADAPTIVE_PASSTHROUGH)) {
+            return child;
+        }
         if (translatorContext.isLocalShuffleFragment()
                 && exchangeType.isHeavyOperation() && 
child.isSerialOperator()) {
             PlanNode ptNode = new 
LocalExchangeNode(translatorContext.nextPlanNodeId(),
diff --git 
a/regression-test/suites/nereids_p0/local_shuffle/test_local_shuffle_rqg_bugs.groovy
 
b/regression-test/suites/nereids_p0/local_shuffle/test_local_shuffle_rqg_bugs.groovy
index d5609f3b133..ba03fcafe97 100644
--- 
a/regression-test/suites/nereids_p0/local_shuffle/test_local_shuffle_rqg_bugs.groovy
+++ 
b/regression-test/suites/nereids_p0/local_shuffle/test_local_shuffle_rqg_bugs.groovy
@@ -1149,5 +1149,77 @@ suite("test_local_shuffle_rqg_bugs") {
         assertTrue(false, "Bug 20: Serial exchange + agg hang: ${t.message}")
     }
 
+    // ============================================================
+    //  Bug 21: Multi-distinct COUNT on many-bucket table → COREDUMP
+    //  RQG build 186737/186929/186952: AggSinkOperatorX::sink → 
set_ready_to_read
+    //  with empty source_deps.
+    //
+    //  Root cause: AGG operators (streaming, distinct-streaming, serialize) 
requested
+    //  PASSTHROUGH from non-ScanNode serial children (Exchange, AGG), 
inserting a
+    //  PASSTHROUGH LE that created a pipeline split disconnecting 
AggSink↔AggSource
+    //  shared state.
+    //
+    //  Fix: restrict AGG PASSTHROUGH requests to ScanNode children only.
+    //  Triggered by: multi-distinct COUNT/MIN with MultiCastDataSinks feeding
+    //  serial UNPARTITIONED Exchanges into streaming AGG fragments.
+    // ============================================================
+    sql "DROP TABLE IF EXISTS rqg_t5_many_buckets"
+    sql """
+        CREATE TABLE rqg_t5_many_buckets (
+            pk INT NOT NULL,
+            col_int_undef_signed INT,
+            col_date_undef_signed DATE,
+            col_date_undef_signed2 DATE,
+            col_varchar_1024__undef_signed VARCHAR(1024)
+        ) ENGINE=OLAP
+        DUPLICATE KEY(pk)
+        DISTRIBUTED BY HASH(pk) BUCKETS 56
+        PROPERTIES ("replication_num" = "1")
+    """
+    sql """INSERT INTO rqg_t5_many_buckets VALUES
+        
(1,1,'2023-12-09','2024-06-01','s1'),(2,2,'2023-03-15','2024-01-20','s2'),
+        
(3,3,'2023-07-22','2024-03-10',NULL),(4,4,'2023-12-09','2024-06-01','s4'),
+        
(5,5,'2023-01-05','2024-09-15','s5'),(6,6,'2023-08-11','2024-02-28','s6'),
+        
(7,7,'2023-04-18','2024-07-04',NULL),(8,8,'2023-11-25','2024-05-12','s8'),
+        
(9,9,'2023-06-30','2024-11-19','s9'),(10,10,'2023-02-14','2024-08-07','s10')
+    """
+
+    try {
+        logger.info("Bug 21: Testing multi-distinct COUNT on many-bucket table 
(COREDUMP fix)")
+        for (int ppt : [4, 6]) {
+            // Test without use_serial_exchange
+            def bug21_baseline = sql """
+                SELECT /*+SET_VAR(enable_local_shuffle_planner=false,
+                                  parallel_pipeline_task_num=${ppt},
+                                  ignore_storage_data_distribution=true,
+                                  enable_sql_cache=false)*/
+                    MIN(distinct col_date_undef_signed),
+                    COUNT(distinct col_date_undef_signed2),
+                    COUNT(distinct col_int_undef_signed)
+                FROM rqg_t5_many_buckets
+                WHERE col_int_undef_signed = col_int_undef_signed
+                LIMIT 1000
+            """
+            def bug21_result = sql """
+                SELECT /*+SET_VAR(enable_local_shuffle_planner=true,
+                                  parallel_pipeline_task_num=${ppt},
+                                  ignore_storage_data_distribution=true,
+                                  enable_sql_cache=false)*/
+                    MIN(distinct col_date_undef_signed),
+                    COUNT(distinct col_date_undef_signed2),
+                    COUNT(distinct col_int_undef_signed)
+                FROM rqg_t5_many_buckets
+                WHERE col_int_undef_signed = col_int_undef_signed
+                LIMIT 1000
+            """
+            assertEquals(bug21_baseline, bug21_result,
+                "Bug 21 pptn=${ppt}: multi-distinct COUNT result mismatch (was 
COREDUMP)")
+        }
+        logger.info("Bug 21: PASSED (no crash, correct results)")
+    } catch (Throwable t) {
+        logger.error("Bug 21 FAILED: ${t.message}")
+        assertTrue(false, "Bug 21: Multi-distinct COUNT COREDUMP: 
${t.message}")
+    }
+
     logger.info("=== All RQG bug reproduction tests completed ===")
 }


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

Reply via email to