Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,6 @@ public class Rewriter extends AbstractBatchJobExecutor {
cascadesContext -> cascadesContext.rewritePlanContainsTypes(LogicalAggregate.class)
|| cascadesContext.rewritePlanContainsTypes(LogicalJoin.class)
|| cascadesContext.rewritePlanContainsTypes(LogicalUnion.class),
custom(RuleType.ELIMINATE_GROUP_BY_KEY_BY_UNIFORM, EliminateGroupByKeyByUniform::new),
topDown(new EliminateGroupByKey()),
topDown(new PushDownAggThroughJoinOnPkFk()),
topDown(new PullUpJoinFromUnionAll())
Expand Down Expand Up @@ -877,6 +876,8 @@ private static List<RewriteJob> getWholeTreeRewriteJobs(
)));
rewriteJobs.addAll(jobs(topic("convert outer join to anti",
custom(RuleType.CONVERT_OUTER_JOIN_TO_ANTI, ConvertOuterJoinToAntiJoin::new))));
rewriteJobs.addAll(jobs(topic("eliminate group by key by uniform",
custom(RuleType.ELIMINATE_GROUP_BY_KEY_BY_UNIFORM, EliminateGroupByKeyByUniform::new))));
if (needOrExpansion) {
rewriteJobs.addAll(jobs(topic("or expansion",
custom(RuleType.OR_EXPANSION, () -> OrExpansion.INSTANCE))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.doris.nereids.jobs.JobContext;
import org.apache.doris.nereids.properties.DataTrait;
import org.apache.doris.nereids.trees.expressions.Alias;
import org.apache.doris.nereids.trees.expressions.CTEId;
import org.apache.doris.nereids.trees.expressions.ExprId;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.NamedExpression;
Expand All @@ -42,7 +41,6 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

/**
Expand All @@ -61,8 +59,7 @@ public class EliminateGroupByKeyByUniform extends DefaultPlanRewriter<Map<ExprId

@Override
public Plan rewriteRoot(Plan plan, JobContext jobContext) {
Optional<CTEId> cteId = jobContext.getCascadesContext().getCurrentTree();
if (cteId.isPresent() || !plan.containsType(Aggregate.class)) {
if (!plan.containsType(Aggregate.class)) {
return plan;
}
Map<ExprId, ExprId> replaceMap = new HashMap<>();
Expand Down Expand Up @@ -104,7 +101,7 @@ public Plan visitLogicalAggregate(LogicalAggregate<? extends Plan> aggregate, Ma
if (removedExpression.isEmpty()) {
return aggregate;
}
/* select 1 c1 from test group by c; -> select 1 c1 from test limit 1 */
/* select 1 c1 from test group by c1; -> select 1 c1 from test limit 1 */
if (newGroupBy.isEmpty() && aggregate.getAggregateFunctions().isEmpty()) {
LogicalProject<Plan> newProject = new LogicalProject<>(
Utils.fastToImmutableList(aggregate.getOutput()), aggregate.child());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,13 +621,14 @@ PhysicalResultSink
-- !union_3_shape --
PhysicalResultSink
--PhysicalLimit[GLOBAL]
----PhysicalUnion
------PhysicalProject[-1 AS `k2`, 3 AS `k1`, c AS `k3`]
--------filter((t1.a = 1) and (t1.b = 2) and (t1.c = 3))
----------PhysicalOlapScan[t1]
------PhysicalProject[-1 AS `k2`, 3 AS `k1`, z AS `k3`]
--------filter((t2.x = 1) and (t2.y = 2) and (t2.z = 3))
----------PhysicalOlapScan[t2]
----PhysicalProject[-1 AS `k2`, 3 AS `k1`, 3 AS `k3`]
------PhysicalUnion
--------PhysicalProject[1 AS `1`]
----------filter((t1.a = 1) and (t1.b = 2) and (t1.c = 3))
------------PhysicalOlapScan[t1]
--------PhysicalProject[1 AS `1`]
----------filter((t2.x = 1) and (t2.y = 2) and (t2.z = 3))
------------PhysicalOlapScan[t2]

-- !union_3_result --
3 -1 3
Expand Down Expand Up @@ -780,10 +781,11 @@ PhysicalResultSink
-- !union_17_shape --
PhysicalResultSink
--PhysicalLimit[GLOBAL]
----PhysicalUnion
------PhysicalProject[3 AS `a + b`, t1.a]
--------filter((t1.a = 1) and (t1.b = 2))
----------PhysicalOlapScan[t1]
----PhysicalProject[1 AS `1`, 3 AS `3`]
------PhysicalUnion
--------PhysicalProject[1 AS `1`]
----------filter((t1.a = 1) and (t1.b = 2))
------------PhysicalOlapScan[t1]

-- !union_17_result --
1 3
Expand All @@ -792,7 +794,8 @@ PhysicalResultSink
PhysicalResultSink
--PhysicalUnion
----PhysicalLimit[GLOBAL]
------PhysicalUnion
------PhysicalProject[1 AS `1`, 3 AS `3`]
--------PhysicalUnion
----PhysicalProject[3 AS `a + b`, t1.a]
------filter((t1.a = 1) and (t1.b = 2))
--------PhysicalOlapScan[t1]
Expand Down