OIiveirra commented on code in PR #71331:
URL: https://github.com/apache/doris/pull/71331#discussion_r4780576310
##########
fe/fe-core/src/main/java/org/apache/doris/planner/AggregationNode.java:
##########
@@ -388,6 +403,46 @@ public Pair<PlanNode, LocalExchangeType>
enforceAndDeriveLocalExchange(
return Pair.of(this, enforceResult.second);
}
+ // Let each scan task contribute partial states when hashing a few groups
would idle tasks.
+ // The outgoing stream routes all partial states for the same group to the
same final reducer.
+ private boolean canDistributePartialGroups(PlanTranslatorContext context) {
+ long tasks = context.getCurrentFragmentMinInstancesPerBe();
+ if (tasks <= 1 || !Double.isFinite(estimatedGroupsForLocalExchange)
+ || estimatedGroupsForLocalExchange <= 0 ||
estimatedGroupsForLocalExchange > tasks
+ || needsFinalize || !aggInfo.isFirstPhase() || sortByGroupKey
!= null || hasLimit()
+ || (projectList != null && !projectList.isEmpty())
+ || !(getChild(0) instanceof FileQueryScanNode) ||
getChild(0).hasLimit()
+ ||
!getChild(0).isSerialOperatorOnBe(context.getConnectContext())
+ || getFragment() == null || getFragment().getPlanRoot() != this
+ || !(getFragment().getSink() instanceof DataStreamSink)) {
+ return false;
+ }
+
+ DataPartition partition = getFragment().getSink().getOutputPartition();
+ List<Expr> keys = aggInfo.getGroupingExprs();
+ if (partition == null || partition.getType() !=
TPartitionType.HASH_PARTITIONED
+ || keys.size() != 2 || partition.getPartitionExprs().size() !=
keys.size()
+ || aggInfo.getOutputTupleDesc().getSlots().size() <
keys.size()) {
+ return false;
+ }
+ for (int i = 0; i < keys.size(); i++) {
+ Expr output = partition.getPartitionExprs().get(i);
+ SlotDescriptor group =
aggInfo.getOutputTupleDesc().getSlots().get(i);
+ if (!(keys.get(i) instanceof SlotRef) ||
!keys.get(i).getType().isStringType()
+ || !(output instanceof SlotRef) || ((SlotRef)
output).getDesc() == null
+ || !group.getId().equals(((SlotRef) output).getSlotId())
+ || !aggInfo.getOutputTupleId().equals(((SlotRef)
output).getDesc().getParentId())) {
+ return false;
+ }
+ }
+
+ List<FunctionCallExpr> aggregates = aggInfo.getAggregateExprs();
+ return !aggregates.isEmpty() && aggregates.stream().allMatch(call ->
+ call.getFn() != null && call.getFn().getBinaryType() ==
Function.BinaryType.BUILTIN
+ && !call.getParams().isDistinct() &&
call.getOrderByElements().isEmpty()
+ &&
MERGEABLE_NUMERIC_AGGREGATES.contains(call.getFnName().getFunction()));
Review Comment:
Fixed in 8451320f8f2. The planner checks the bound SUM/AVG input type and
keeps floating-point and DecimalV2 overloads on local hash. COUNT, integer
SUM/AVG and DecimalV3 SUM/AVG remain eligible. The new planner tests cover both
paths.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java:
##########
@@ -1313,6 +1315,15 @@ public PlanFragment visitPhysicalHashAggregate(
setPlanRoot(inputPlanFragment, aggregationNode, aggregate);
if (aggregate.getStats() != null) {
aggregationNode.setCardinality((long)
aggregate.getStats().getRowCount());
+ Statistics input = aggregate.child().getStats();
+ if (input != null && aggregate.getGroupByExpressions().size() == 2
+ && aggregate.getGroupByExpressions().stream().allMatch(key
-> {
+ ColumnStatistic column =
input.findColumnStatistics(key);
+ return key instanceof SlotReference && column != null
&& !column.isUnKnown
+ && Double.isFinite(column.ndv) && column.ndv >
0;
+ })) {
+
aggregationNode.setEstimatedGroupsForLocalExchange(aggregate.getStats().getRowCount());
Review Comment:
Fixed in 8451320f8f2. The grouping NDVs are not keyed by snapshot, so a file
scan with a snapshot or scan selector now keeps local hash. The planner test
covers version ID, timestamp and a named branch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]