[Fix](inverted index) fix wrong opt for count_on_index #41127 (#41154)

cherry pick from #41127
This commit is contained in:
airborne12
2024-09-23 22:45:52 +08:00
committed by GitHub
parent 5bcea1983d
commit 48e60f3ff3
4 changed files with 145 additions and 5 deletions

View File

@ -117,7 +117,8 @@ public class AggregateStrategies implements ImplementationRuleFactory {
.when(agg -> {
Set<AggregateFunction> funcs = agg.getAggregateFunctions();
return !funcs.isEmpty() && funcs.stream()
.allMatch(f -> f instanceof Count && !f.isDistinct());
.allMatch(f -> f instanceof Count && !f.isDistinct() && (((Count) f).isCountStar()
|| f.child(0) instanceof Slot));
})
.thenApply(ctx -> {
LogicalAggregate<LogicalFilter<LogicalOlapScan>> agg = ctx.root;
@ -136,7 +137,8 @@ public class AggregateStrategies implements ImplementationRuleFactory {
.when(agg -> agg.getGroupByExpressions().isEmpty())
.when(agg -> {
Set<AggregateFunction> funcs = agg.getAggregateFunctions();
return !funcs.isEmpty() && funcs.stream().allMatch(f -> f instanceof Count && !f.isDistinct());
return !funcs.isEmpty() && funcs.stream().allMatch(f -> f instanceof Count && !f.isDistinct()
&& (((Count) f).isCountStar() || f.child(0) instanceof Slot));
})
.thenApply(ctx -> {
LogicalAggregate<LogicalProject<LogicalFilter<LogicalOlapScan>>> agg = ctx.root;