[opt](Nereids) remove group by key eliminate rule option (#32238)
This commit is contained in:
@ -328,7 +328,7 @@ public class Rewriter extends AbstractBatchJobExecutor {
|
||||
custom(RuleType.ELIMINATE_UNNECESSARY_PROJECT, EliminateUnnecessaryProject::new)
|
||||
),
|
||||
|
||||
// this rule should invoke after topic "Join pull up"
|
||||
// this rule should be invoked after topic "Join pull up"
|
||||
topic("eliminate group by keys according to fd items",
|
||||
topDown(new EliminateGroupByKey())
|
||||
),
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package org.apache.doris.nereids.rules.rewrite;
|
||||
|
||||
import org.apache.doris.nereids.jobs.JobContext;
|
||||
import org.apache.doris.nereids.rules.RuleType;
|
||||
import org.apache.doris.nereids.rules.rewrite.ColumnPruning.PruneContext;
|
||||
import org.apache.doris.nereids.trees.expressions.Alias;
|
||||
import org.apache.doris.nereids.trees.expressions.Expression;
|
||||
@ -40,7 +39,6 @@ import org.apache.doris.nereids.trees.plans.logical.OutputPrunable;
|
||||
import org.apache.doris.nereids.trees.plans.visitor.CustomRewriter;
|
||||
import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanRewriter;
|
||||
import org.apache.doris.nereids.util.ExpressionUtils;
|
||||
import org.apache.doris.qe.ConnectContext;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@ -207,16 +205,8 @@ public class ColumnPruning extends DefaultPlanRewriter<PruneContext> implements
|
||||
private Plan pruneAggregate(Aggregate agg, PruneContext context) {
|
||||
// first try to prune group by and aggregate functions
|
||||
Aggregate prunedOutputAgg = pruneOutput(agg, agg.getOutputs(), agg::pruneOutputs, context);
|
||||
Set<Integer> enableNereidsRules = ConnectContext.get().getSessionVariable().getEnableNereidsRules();
|
||||
Aggregate fillUpAggr;
|
||||
|
||||
if (!enableNereidsRules.contains(RuleType.ELIMINATE_GROUP_BY_KEY.type())) {
|
||||
fillUpAggr = fillUpGroupByToOutput(prunedOutputAgg)
|
||||
.map(fullOutput -> prunedOutputAgg.withAggOutput(fullOutput))
|
||||
.orElse(prunedOutputAgg);
|
||||
} else {
|
||||
fillUpAggr = fillUpGroupByAndOutput(prunedOutputAgg);
|
||||
}
|
||||
Aggregate fillUpAggr = fillUpGroupByAndOutput(prunedOutputAgg);
|
||||
|
||||
return pruneChildren(fillUpAggr);
|
||||
}
|
||||
@ -229,23 +219,6 @@ public class ColumnPruning extends DefaultPlanRewriter<PruneContext> implements
|
||||
return pruneChildren(plan, requireAllOutputOfChildren);
|
||||
}
|
||||
|
||||
private static Optional<List<NamedExpression>> fillUpGroupByToOutput(Aggregate prunedOutputAgg) {
|
||||
List<Expression> groupBy = prunedOutputAgg.getGroupByExpressions();
|
||||
List<NamedExpression> output = prunedOutputAgg.getOutputExpressions();
|
||||
|
||||
if (output.containsAll(groupBy)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
List<NamedExpression> aggFunctions = Lists.newArrayList(output);
|
||||
aggFunctions.removeAll(groupBy);
|
||||
|
||||
return Optional.of(ImmutableList.<NamedExpression>builder()
|
||||
.addAll((List) groupBy)
|
||||
.addAll(aggFunctions)
|
||||
.build());
|
||||
}
|
||||
|
||||
private static Aggregate fillUpGroupByAndOutput(Aggregate prunedOutputAgg) {
|
||||
List<Expression> groupBy = prunedOutputAgg.getGroupByExpressions();
|
||||
List<NamedExpression> output = prunedOutputAgg.getOutputExpressions();
|
||||
|
||||
@ -25,7 +25,6 @@ import org.apache.doris.nereids.trees.expressions.NamedExpression;
|
||||
import org.apache.doris.nereids.trees.expressions.SlotReference;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
|
||||
import org.apache.doris.qe.ConnectContext;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
@ -42,10 +41,6 @@ public class EliminateGroupByKey extends OneRewriteRuleFactory {
|
||||
@Override
|
||||
public Rule build() {
|
||||
return logicalAggregate(logicalProject()).then(agg -> {
|
||||
Set<Integer> enableNereidsRules = ConnectContext.get().getSessionVariable().getEnableNereidsRules();
|
||||
if (!enableNereidsRules.contains(RuleType.ELIMINATE_GROUP_BY_KEY.type())) {
|
||||
return null;
|
||||
}
|
||||
LogicalPlan childPlan = agg.child();
|
||||
List<FdItem> uniqueFdItems = new ArrayList<>();
|
||||
List<FdItem> nonUniqueFdItems = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user