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

yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.0 by this push:
     new d3e56dd7538 branch-4.0: [fix](nereids) deduplicate scope slots #58683 
(#61270)
d3e56dd7538 is described below

commit d3e56dd7538631dac65d4a643e2b94155ad670af
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Mar 13 20:05:38 2026 +0800

    branch-4.0: [fix](nereids) deduplicate scope slots #58683 (#61270)
    
    Cherry-picked from #58683
    
    Co-authored-by: minghong <[email protected]>
---
 .../nereids/rules/analysis/ExpressionAnalyzer.java |  4 ++
 .../nereids_p0/slot_bind/test_bind_slot.groovy     | 47 ++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java
index fdb709516ea..330a238995d 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java
@@ -274,7 +274,11 @@ public class ExpressionAnalyzer extends 
SubExprAnalyzer<ExpressionRewriteContext
         if (bindSlotInOuterScope && !foundInThisScope && 
outerScope.isPresent()) {
             boundedOpt = Optional.of(bindSlotByScope(unboundSlot, 
outerScope.get()));
         }
+        // it is heavy to deduplicate slots in scope. So we deduplicates 
bounded here
         List<? extends Expression> bounded = boundedOpt.get();
+        if (bounded.size() > 1) {
+            bounded = bounded.stream().distinct().collect(Collectors.toList());
+        }
         switch (bounded.size()) {
             case 0:
                 String tableName = 
StringUtils.join(unboundSlot.getQualifier(), ".");
diff --git a/regression-test/suites/nereids_p0/slot_bind/test_bind_slot.groovy 
b/regression-test/suites/nereids_p0/slot_bind/test_bind_slot.groovy
new file mode 100644
index 00000000000..6d49c7fb49a
--- /dev/null
+++ b/regression-test/suites/nereids_p0/slot_bind/test_bind_slot.groovy
@@ -0,0 +1,47 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+
+suite("test_bind_slot") {
+    sql """
+      drop table if exists t; 
+       CREATE TABLE t (
+      `id` int COMMENT '',
+      `status` string COMMENT '',
+      `time_created` string COMMENT '',
+    )  properties("replication_num" = "1");
+
+  """
+  // if scope is not deduplicated, time_created wil be bound twice, causing a 
slot ambigious error
+  sql """select
+          from_unixtime(time_created / 1000, 'yyyyMMdd') as date1,
+          status,
+          count(distinct id) as cnt
+          from
+            (
+              select
+                from_unixtime(time_created / 1001) as created_date,
+                time_created,
+                *
+              from
+                t
+            ) t1
+          group by
+          from_unixtime(time_created / 1000, 'yyyyMMdd'),
+          status;
+  """
+}


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

Reply via email to