morrySnow commented on code in PR #41772: URL: https://github.com/apache/doris/pull/41772#discussion_r1802978303
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java: ########## @@ -541,26 +541,58 @@ private LogicalAggregate<? extends Plan> pushdownCountOnIndex( LogicalFilter<? extends Plan> filter, LogicalOlapScan olapScan, CascadesContext cascadesContext) { - PhysicalOlapScan physicalOlapScan - = (PhysicalOlapScan) new LogicalOlapScanToPhysicalOlapScan() + + PhysicalOlapScan physicalOlapScan = (PhysicalOlapScan) new LogicalOlapScanToPhysicalOlapScan() .build() .transform(olapScan, cascadesContext) .get(0); + + List<Expression> argumentsOfAggregateFunction = normalizeArguments(agg.getAggregateFunctions(), project); + + if (!onlyContainsSlotOrNumericCastSlot(argumentsOfAggregateFunction)) { + return agg; + } + + return agg.withChildren(ImmutableList.of( + project != null + ? project.withChildren(ImmutableList.of( + filter.withChildren(ImmutableList.of( + new PhysicalStorageLayerAggregate( + physicalOlapScan, PushDownAggOp.COUNT_ON_MATCH))))) + : filter.withChildren(ImmutableList.of( + new PhysicalStorageLayerAggregate( + physicalOlapScan, PushDownAggOp.COUNT_ON_MATCH))) + )); + } + + private List<Expression> normalizeArguments(Set<AggregateFunction> aggregateFunctions, + @Nullable LogicalProject<? extends Plan> project) { + List<Expression> arguments = aggregateFunctions.stream() + .flatMap(aggregateFunction -> aggregateFunction.getArguments().stream()) + .collect(ImmutableList.toImmutableList()); + if (project != null) { - return agg.withChildren(ImmutableList.of( - project.withChildren(ImmutableList.of( - filter.withChildren(ImmutableList.of( - new PhysicalStorageLayerAggregate( - physicalOlapScan, - PushDownAggOp.COUNT_ON_MATCH))))) - )); - } else { - return agg.withChildren(ImmutableList.of( - filter.withChildren(ImmutableList.of( - new PhysicalStorageLayerAggregate( - physicalOlapScan, - PushDownAggOp.COUNT_ON_MATCH))))); + arguments = Project.findProject(arguments, project.getProjects()) Review Comment: +1 -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org