[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
This commit is contained in:
starocean999
2023-08-04 15:21:18 +08:00
committed by GitHub
parent b9e344617a
commit d379b04b39
2 changed files with 25 additions and 2 deletions

View File

@ -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());
}