[minor](Nereids): enable PushDownTopNDistinctThroughJoin (#30275)
This commit is contained in:
@ -109,6 +109,7 @@ import org.apache.doris.nereids.rules.rewrite.PushDownMinMaxThroughJoin;
|
||||
import org.apache.doris.nereids.rules.rewrite.PushDownSumThroughJoin;
|
||||
import org.apache.doris.nereids.rules.rewrite.PushDownSumThroughJoinOneSide;
|
||||
import org.apache.doris.nereids.rules.rewrite.PushDownTopNDistinctThroughJoin;
|
||||
import org.apache.doris.nereids.rules.rewrite.PushDownTopNDistinctThroughUnion;
|
||||
import org.apache.doris.nereids.rules.rewrite.PushDownTopNThroughJoin;
|
||||
import org.apache.doris.nereids.rules.rewrite.PushDownTopNThroughUnion;
|
||||
import org.apache.doris.nereids.rules.rewrite.PushDownTopNThroughWindow;
|
||||
@ -334,7 +335,7 @@ public class Rewriter extends AbstractBatchJobExecutor {
|
||||
new PushDownLimitDistinctThroughJoin(),
|
||||
new PushDownLimitDistinctThroughUnion(),
|
||||
new PushDownTopNDistinctThroughJoin(),
|
||||
// new PushDownTopNDistinctThroughUnion(),
|
||||
new PushDownTopNDistinctThroughUnion(),
|
||||
new PushDownTopNThroughJoin(),
|
||||
new PushDownTopNThroughWindow(),
|
||||
new PushDownTopNThroughUnion()
|
||||
|
||||
@ -271,8 +271,7 @@ public enum RuleType {
|
||||
PUSH_DOWN_TOP_N_THROUGH_PROJECT_WINDOW(RuleTypeClass.REWRITE),
|
||||
PUSH_DOWN_TOP_N_THROUGH_WINDOW(RuleTypeClass.REWRITE),
|
||||
PUSH_DOWN_TOP_N_THROUGH_UNION(RuleTypeClass.REWRITE),
|
||||
PUSH_DOWN_TOP_N_LIMIT_THROUGH_UNION(RuleTypeClass.REWRITE),
|
||||
// limit distinct push down
|
||||
PUSH_DOWN_TOP_N_DISTINCT_THROUGH_UNION(RuleTypeClass.REWRITE),
|
||||
PUSH_DOWN_LIMIT_DISTINCT_THROUGH_JOIN(RuleTypeClass.REWRITE),
|
||||
PUSH_DOWN_LIMIT_DISTINCT_THROUGH_PROJECT_JOIN(RuleTypeClass.REWRITE),
|
||||
PUSH_DOWN_LIMIT_DISTINCT_THROUGH_UNION(RuleTypeClass.REWRITE),
|
||||
|
||||
@ -28,6 +28,7 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalTopN;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalUnion;
|
||||
import org.apache.doris.nereids.util.ExpressionUtils;
|
||||
import org.apache.doris.nereids.util.PlanUtils;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
@ -73,20 +74,19 @@ public class PushDownTopNDistinctThroughUnion implements RewriteRuleFactory {
|
||||
NamedExpression output = union.getOutputs().get(i);
|
||||
replaceMap.put(output, child.getOutput().get(i));
|
||||
}
|
||||
|
||||
List<OrderKey> orderKeys = topN.getOrderKeys().stream()
|
||||
.map(orderKey -> orderKey.withExpression(
|
||||
ExpressionUtils.replace(orderKey.getExpr(), replaceMap)))
|
||||
.collect(ImmutableList.toImmutableList());
|
||||
newChildren.add(
|
||||
new LogicalTopN<>(orderKeys, topN.getLimit() + topN.getOffset(), 0, child));
|
||||
newChildren.add(new LogicalTopN<>(orderKeys, topN.getLimit() + topN.getOffset(), 0,
|
||||
PlanUtils.distinct(child)));
|
||||
}
|
||||
if (union.children().equals(newChildren)) {
|
||||
return null;
|
||||
}
|
||||
return topN.withChildren(agg.withChildren(union.withChildren(newChildren)));
|
||||
})
|
||||
.toRule(RuleType.PUSH_DOWN_TOP_N_THROUGH_UNION)
|
||||
.toRule(RuleType.PUSH_DOWN_TOP_N_DISTINCT_THROUGH_UNION)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +73,11 @@ public class PlanUtils {
|
||||
}
|
||||
|
||||
public static LogicalAggregate<Plan> distinct(Plan plan) {
|
||||
return new LogicalAggregate<>(ImmutableList.copyOf(plan.getOutput()), false, plan);
|
||||
if (plan instanceof LogicalAggregate && ((LogicalAggregate<?>) plan).isDistinct()) {
|
||||
return (LogicalAggregate<Plan>) plan;
|
||||
} else {
|
||||
return new LogicalAggregate<>(ImmutableList.copyOf(plan.getOutput()), false, plan);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user