Skip to content

Commit

Permalink
[opt](Nereids) use 1 instead narrowest column when do column pruning (a…
Browse files Browse the repository at this point in the history
…pache#41548)

pick from master apache#41548
  • Loading branch information
morrySnow committed Oct 28, 2024
1 parent 5af078b commit e85ebaf
Show file tree
Hide file tree
Showing 19 changed files with 200 additions and 194 deletions.
3 changes: 0 additions & 3 deletions be/src/pipeline/exec/table_function_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,6 @@ TableFunctionOperatorX::TableFunctionOperatorX(ObjectPool* pool, const TPlanNode

Status TableFunctionOperatorX::_prepare_output_slot_ids(const TPlanNode& tnode) {
// Prepare output slot ids
if (tnode.table_function_node.outputSlotIds.empty()) {
return Status::InternalError("Output slots of table function node is empty");
}
SlotId max_id = -1;
for (auto slot_id : tnode.table_function_node.outputSlotIds) {
if (slot_id > max_id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.functions.NoneMovableFunction;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Uuid;
import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.PlanType;
import org.apache.doris.nereids.trees.plans.algebra.Project;
Expand Down Expand Up @@ -87,7 +88,7 @@ private LogicalProject(List<NamedExpression> projects, List<NamedExpression> exc
Preconditions.checkArgument(!projects.isEmpty() || !(child instanceof Unbound),
"projects can not be empty when child plan is unbound");
this.projects = projects.isEmpty()
? ImmutableList.of(ExpressionUtils.selectMinimumColumn(child.get(0).getOutput()))
? ImmutableList.of(new Alias(new TinyIntLiteral((byte) 1)))
: projects;
this.projectsSet = Suppliers.memoize(() -> ImmutableSet.copyOf(this.projects));
this.excepts = Utils.fastToImmutableList(excepts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void testCountStarProject() {
logicalAggregate(
logicalProject().when(
project -> project.getProjects().size() == 1
&& project.getProjects().get(0) instanceof SlotReference
&& "o_orderdate".equals(project.getProjects().get(0).toSql()))))
&& !(project.getProjects().get(0) instanceof SlotReference)
)))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
package org.apache.doris.nereids.rules.rewrite;

import org.apache.doris.nereids.trees.expressions.NamedExpression;
import org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
import org.apache.doris.nereids.types.DoubleType;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.TinyIntType;
import org.apache.doris.nereids.util.MemoPatternMatchSupported;
import org.apache.doris.nereids.util.PlanChecker;
import org.apache.doris.utframe.TestWithFeService;
Expand Down Expand Up @@ -188,7 +189,7 @@ public void pruneCountStarStmt() {
logicalAggregate(
logicalProject(
logicalOlapScan()
).when(p -> p.getProjects().get(0).getDataType().equals(IntegerType.INSTANCE)
).when(p -> p.getProjects().get(0).getDataType().equals(TinyIntType.INSTANCE)
&& p.getProjects().size() == 1)
)
);
Expand All @@ -203,7 +204,7 @@ public void pruneCountConstantStmt() {
logicalAggregate(
logicalProject(
logicalOlapScan()
).when(p -> p.getProjects().get(0).getDataType().equals(IntegerType.INSTANCE)
).when(p -> p.getProjects().get(0).getDataType().equals(TinyIntType.INSTANCE)
&& p.getProjects().size() == 1)
)
);
Expand All @@ -218,7 +219,7 @@ public void pruneCountConstantAndSumConstantStmt() {
logicalAggregate(
logicalProject(
logicalOlapScan()
).when(p -> p.getProjects().get(0).getDataType().equals(IntegerType.INSTANCE)
).when(p -> p.getProjects().get(0).getDataType().equals(TinyIntType.INSTANCE)
&& p.getProjects().size() == 1)
)
);
Expand All @@ -233,7 +234,7 @@ public void pruneCountStarAndSumConstantStmt() {
logicalAggregate(
logicalProject(
logicalOlapScan()
).when(p -> p.getProjects().get(0).getDataType().equals(IntegerType.INSTANCE)
).when(p -> p.getProjects().get(0).getDataType().equals(TinyIntType.INSTANCE)
&& p.getProjects().size() == 1)
)
);
Expand Down Expand Up @@ -283,9 +284,7 @@ public void pruneColumnForOneSideOnCrossJoin() {
"internal.test.student.id",
"internal.test.student.name"))),
logicalProject(logicalRelation())
.when(p -> getOutputQualifiedNames(p)
.containsAll(ImmutableList.of(
"internal.test.score.sid")))
.when(p -> p.getProjects().stream().noneMatch(SlotReference.class::isInstance))
)
)
);
Expand Down
Loading

0 comments on commit e85ebaf

Please sign in to comment.