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 b0ee988a683420..666b131061ec7d 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 @@ -373,16 +373,25 @@ public Set computeInputSlotIds(Analyzer analyzer) throws NotImplementedE if (!tupleDesc.getMaterializedSlots().isEmpty()) { result.add(tupleDesc.getMaterializedSlots().get(0).getId()); } - } - // if some input slot for aggregate slot which is not materialized, we need to remove it from the result - TupleDescriptor tupleDescriptor = aggInfo.getOutputTupleDesc(); - ArrayList slots = tupleDescriptor.getSlots(); - for (SlotDescriptor slot : slots) { - if (!slot.isMaterialized()) { - List unRequestIds = Lists.newArrayList(); - Expr.getIds(slot.getSourceExprs(), null, unRequestIds); - unRequestIds.forEach(result::remove); + } else { + // if some input slot for aggregate slot which is not materialized, we need to remove it from the result + TupleDescriptor tupleDescriptor = aggInfo.getOutputTupleDesc(); + ArrayList slots = tupleDescriptor.getSlots(); + Set allUnRequestIds = Sets.newHashSet(); + Set allRequestIds = Sets.newHashSet(); + for (SlotDescriptor slot : slots) { + if (!slot.isMaterialized()) { + List unRequestIds = Lists.newArrayList(); + Expr.getIds(slot.getSourceExprs(), null, unRequestIds); + allUnRequestIds.addAll(unRequestIds); + } else { + List requestIds = Lists.newArrayList(); + Expr.getIds(slot.getSourceExprs(), null, requestIds); + allRequestIds.addAll(requestIds); + } } + allRequestIds.forEach(allUnRequestIds::remove); + allUnRequestIds.forEach(result::remove); } return result; } diff --git a/regression-test/data/correctness_p0/test_inlineview_with_project.out b/regression-test/data/correctness_p0/test_inlineview_with_project.out index 20135da100ad25..fad0b3fe4460a5 100644 --- a/regression-test/data/correctness_p0/test_inlineview_with_project.out +++ b/regression-test/data/correctness_p0/test_inlineview_with_project.out @@ -23,3 +23,6 @@ 2 3 +-- !select5 -- +3 + diff --git a/regression-test/suites/correctness_p0/test_inlineview_with_project.groovy b/regression-test/suites/correctness_p0/test_inlineview_with_project.groovy index c97b351f296dcc..78eb76b5c42cbf 100644 --- a/regression-test/suites/correctness_p0/test_inlineview_with_project.groovy +++ b/regression-test/suites/correctness_p0/test_inlineview_with_project.groovy @@ -562,6 +562,47 @@ suite("test_inlineview_with_project") { order by 1; """ + qt_select5 """ + select + count(*) + from + ( + select + random(), + group_concat(cast(ga.column3 as varchar)) as column111 + from + ( + select + t1.id as id, + upper(t1.caseId) as column1, + t1.content as column3 + from + ( + select + id, + caseId, + content + from + dr_user_test_t2 + limit + 10 + ) t1 + left join ( + select + id, + caseId, + content + from + dr_user_test_t2 + limit + 10 + ) t2 on t1.id = t2.id + ) as ga + group by + lower(ga.column3) + ) as a; + """ + sql """DROP TABLE IF EXISTS `dr_user_test_t1`;""" sql """DROP TABLE IF EXISTS `dr_user_test_t2`;""" }