This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new d379b04b39 [fix](planner) fix bug of push conjuncts through second
phase agg (#22417)
d379b04b39 is described below
commit d379b04b3989c81c14d36d3909871d86f8e4baa2
Author: starocean999 <[email protected]>
AuthorDate: Fri Aug 4 15:21:18 2023 +0800
[fix](planner) fix bug of push conjuncts through second phase agg (#22417)
If there is a second phase agg, the output of the 1st phase agg is its
intermediate tuple not the output tuple.
This pr fix it
---
.../java/org/apache/doris/planner/SingleNodePlanner.java | 13 +++++++++++--
.../suites/correctness_p0/test_distinct_agg.groovy | 14 ++++++++++++++
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java
b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java
index 3bce97a0c4..7cc6ae7cd2 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java
@@ -2687,7 +2687,12 @@ public class SingleNodePlanner {
if (aggregateInfo == null ||
aggregateInfo.getGroupingExprs().isEmpty()) {
return;
}
- final List<Expr> predicates = getBoundPredicates(analyzer,
aggregateInfo.getOutputTupleDesc());
+ // The output of the 1st phase agg is the 1st phase intermediate.
+ // see createSecondPhaseAggInfo method
+ final List<Expr> predicates = getBoundPredicates(analyzer,
+ aggregateInfo.getSecondPhaseDistinctAggInfo() != null
+ ? aggregateInfo.getIntermediateTupleDesc()
+ : aggregateInfo.getOutputTupleDesc());
if (predicates.isEmpty()) {
return;
}
@@ -2713,7 +2718,11 @@ public class SingleNodePlanner {
}
final AggregateInfo secondPhaseAggInfo =
firstPhaseAggInfo.getSecondPhaseDistinctAggInfo();
- final List<TupleId> firstPhaseTupleIds =
Lists.newArrayList(firstPhaseAggInfo.getOutputTupleId());
+ // The output of the 1st phase agg is the 1st phase intermediate.
+ // see createSecondPhaseAggInfo method
+ final List<TupleId> firstPhaseTupleIds = Lists.newArrayList(
+ secondPhaseAggInfo != null ?
firstPhaseAggInfo.getIntermediateTupleId()
+ : firstPhaseAggInfo.getOutputTupleId());
pushDownPredicatesPastAggregationOnePhase(secondPhaseAggInfo,
analyzer, stmt, firstPhaseTupleIds);
pushDownPredicatesPastAggregationOnePhase(firstPhaseAggInfo, analyzer,
stmt, stmt.getTableRefIds());
}
diff --git a/regression-test/suites/correctness_p0/test_distinct_agg.groovy
b/regression-test/suites/correctness_p0/test_distinct_agg.groovy
index 8c80c9f184..ea2cd1f4a4 100644
--- a/regression-test/suites/correctness_p0/test_distinct_agg.groovy
+++ b/regression-test/suites/correctness_p0/test_distinct_agg.groovy
@@ -55,4 +55,18 @@ suite("test_distinct_agg") {
'''
result([['1', '2023-01-10', 1L]])
}
+
+ sql '''SELECT `b`.`dt` AS `dt`
+ FROM
+ (SELECT `dt`AS `dt`,
+ count(DISTINCT `role_id`) AS `pay_role`,
+ avg(`cost`) AS `avg_cost`
+ FROM
+ (SELECT `k6` AS `dt`,
+ `k1` AS `role_id`,
+ sum(CAST(`k2` AS INT)) AS `cost`
+ FROM `t`
+ GROUP BY `dt`, `role_id`) a
+ GROUP BY `dt`) b
+ WHERE `dt` = '2023-06-18';'''
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]