-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] eliminate unnecessary project (#49724)
Signed-off-by: before-Sunrise <[email protected]> (cherry picked from commit 8921afd) # Conflicts: # fe/fe-core/src/test/java/com/starrocks/planner/MaterializedViewManualTest.java # fe/fe-core/src/test/java/com/starrocks/sql/plan/EliminateConstantValueTest.java # fe/fe-core/src/test/java/com/starrocks/sql/plan/JoinTest.java # fe/fe-core/src/test/java/com/starrocks/sql/plan/PruneComplexSubfieldTest.java # fe/fe-core/src/test/java/com/starrocks/sql/plan/SelectConstTest.java
- Loading branch information
1 parent
3cd0732
commit d56bcda
Showing
22 changed files
with
773 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...e-core/src/main/java/com/starrocks/sql/optimizer/rule/tree/InlineCteProjectPruneRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.starrocks.sql.optimizer.rule.tree; | ||
|
||
import com.starrocks.sql.optimizer.OptExpression; | ||
import com.starrocks.sql.optimizer.OptExpressionVisitor; | ||
import com.starrocks.sql.optimizer.operator.Projection; | ||
import com.starrocks.sql.optimizer.operator.physical.PhysicalNoCTEOperator; | ||
import com.starrocks.sql.optimizer.operator.physical.PhysicalOperator; | ||
import com.starrocks.sql.optimizer.task.TaskContext; | ||
|
||
public class InlineCteProjectPruneRule implements TreeRewriteRule { | ||
private static final InlineCteProjectPruneRuleVisitor HANDLER = new InlineCteProjectPruneRuleVisitor(); | ||
|
||
@Override | ||
public OptExpression rewrite(OptExpression root, TaskContext taskContext) { | ||
root.getOp().accept(HANDLER, root, taskContext); | ||
return root; | ||
} | ||
|
||
private static class InlineCteProjectPruneRuleVisitor extends OptExpressionVisitor<Void, TaskContext> { | ||
@Override | ||
public Void visit(OptExpression opt, TaskContext context) { | ||
for (OptExpression input : opt.getInputs()) { | ||
input.getOp().accept(this, input, context); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Void visitPhysicalNoCTE(OptExpression opt, TaskContext context) { | ||
PhysicalNoCTEOperator op = (PhysicalNoCTEOperator) opt.getOp(); | ||
if (op.getProjection() == null) { | ||
visit(opt, context); | ||
return null; | ||
} | ||
Projection parentProjection = op.getProjection(); | ||
|
||
PhysicalOperator child = (PhysicalOperator) opt.getInputs().get(0).getOp(); | ||
if (child.getProjection() == null) { | ||
visit(opt, context); | ||
return null; | ||
} | ||
|
||
Projection childProjection = child.getProjection(); | ||
if (!parentProjection.getUsedColumns().containsAny(childProjection.getOutputColumns())) { | ||
child.setProjection(null); | ||
} | ||
|
||
visit(opt, context); | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.