You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/12/01 09:17:06 UTC
[GitHub] [doris] englefly opened a new pull request, #14730: [feature](nereids)merge proj-proj in post process
englefly opened a new pull request, #14730:
URL: https://github.com/apache/doris/pull/14730
# Proposed changes
this pr guarantees that the physical plan does not contains consecutive physical projects.
Like rewrite rule "merge projects", it works on physical plan, not logical plan.
@morrySnow @sohardforaname PTAL
@sohardforaname I am not sure this pr breaks your previous pr on merge-projects
Issue Number: close #xxx
## Problem summary
Describe your changes.
## Checklist(Required)
1. Does it affect the original behavior:
- [ ] Yes
- [ ] No
- [ ] I don't know
2. Has unit tests been added:
- [ ] Yes
- [ ] No
- [ ] No Need
3. Has document been added or modified:
- [ ] Yes
- [ ] No
- [ ] No Need
4. Does it need to update dependencies:
- [ ] Yes
- [ ] No
5. Are there any changes that cannot be rolled back:
- [ ] Yes (If Yes, please explain WHY)
- [ ] No
## Further comments
If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [doris] englefly commented on a diff in pull request #14730: [feature](nereids)merge proj-proj in post process
Posted by GitBox <gi...@apache.org>.
englefly commented on code in PR #14730:
URL: https://github.com/apache/doris/pull/14730#discussion_r1038784565
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Project.java:
##########
@@ -55,4 +58,79 @@ default Map<Slot, Expression> getAliasToProducer() {
)
);
}
+
+ /**
+ * combine upper level and bottom level projections
+ * 1. alias combination, for example
+ * proj(x as y, b) --> proj(a as x, b, c) =>(a as y, b)
+ * 2. remove used projection in bottom project
+ * @param childProject bottom project
+ * @return project list for merged project
+ */
+ default List<NamedExpression> mergeProjections(Project childProject) {
Review Comment:
could you explain some reason?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [doris] englefly commented on a diff in pull request #14730: [feature](nereids)merge proj-proj in post process
Posted by GitBox <gi...@apache.org>.
englefly commented on code in PR #14730:
URL: https://github.com/apache/doris/pull/14730#discussion_r1037109707
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/MergeProjects.java:
##########
@@ -92,7 +95,7 @@ public Expression visit(Expression expr, Map<Expression, Expression> substitutio
Slot ref = ((SlotReference) expr).withQualifier(Collections.emptyList());
if (substitutionMap.containsKey(ref)) {
Alias res = (Alias) substitutionMap.get(ref);
- return res.child();
+ return new Alias(res.child(), ref.getName());
Review Comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [doris] sohardforaname commented on pull request #14730: [feature](nereids)merge proj-proj in post process
Posted by GitBox <gi...@apache.org>.
sohardforaname commented on PR #14730:
URL: https://github.com/apache/doris/pull/14730#issuecomment-1333544557
It seems OK if ut and p0, p1 pass. Take it easy and change it as your idea.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [doris] morrySnow commented on a diff in pull request #14730: [feature](nereids)merge proj-proj in post process
Posted by GitBox <gi...@apache.org>.
morrySnow commented on code in PR #14730:
URL: https://github.com/apache/doris/pull/14730#discussion_r1037973927
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/Project.java:
##########
@@ -55,4 +58,79 @@ default Map<Slot, Expression> getAliasToProducer() {
)
);
}
+
+ /**
+ * combine upper level and bottom level projections
+ * 1. alias combination, for example
+ * proj(x as y, b) --> proj(a as x, b, c) =>(a as y, b)
+ * 2. remove used projection in bottom project
+ * @param childProject bottom project
+ * @return project list for merged project
+ */
+ default List<NamedExpression> mergeProjections(Project childProject) {
Review Comment:
nit: maybe a static function is better
```sql
List<NamedExpression> mergeProjections(List<NamedExpression> top, List<NamedExpression> bottom)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [doris] morrySnow merged pull request #14730: [feature](nereids)merge proj-proj in post process
Posted by GitBox <gi...@apache.org>.
morrySnow merged PR #14730:
URL: https://github.com/apache/doris/pull/14730
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [doris] englefly commented on a diff in pull request #14730: [feature](nereids)merge proj-proj in post process
Posted by GitBox <gi...@apache.org>.
englefly commented on code in PR #14730:
URL: https://github.com/apache/doris/pull/14730#discussion_r1037729861
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/MergeProjectPostProcessor.java:
##########
@@ -0,0 +1,60 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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
+//
+// http://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 org.apache.doris.nereids.processor.post;
+
+import org.apache.doris.nereids.CascadesContext;
+import org.apache.doris.nereids.rules.rewrite.logical.MergeProjects;
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalProject;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * merge consecutive projects
+ */
+public class MergeProjectPostProcessor extends PlanPostProcessor {
+
+ @Override
+ public PhysicalProject visitPhysicalProject(PhysicalProject<? extends Plan> project, CascadesContext ctx) {
+ Plan child = project.child();
+ child = child.accept(this, ctx);
+ if (child instanceof PhysicalProject) {
+ Map<Expression, Expression> aliasMap = getAliasProjections((PhysicalProject) child);
+ List<NamedExpression> projections = project.getProjects();
+ projections = projections.stream()
+ .map(e -> MergeProjects.ExpressionReplacer.INSTANCE.visit(e, aliasMap))
+ .map(NamedExpression.class::cast)
+ .collect(Collectors.toList());
+ return project.withProjectionsAndChild(projections, child.child(0));
+ }
+ return project;
Review Comment:
Good suggestion. Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [doris] hello-stephen commented on pull request #14730: [feature](nereids)merge proj-proj in post process
Posted by GitBox <gi...@apache.org>.
hello-stephen commented on PR #14730:
URL: https://github.com/apache/doris/pull/14730#issuecomment-1333533551
TeamCity pipeline, clickbench performance test result:
the sum of best hot time: 34.73 seconds
load time: 435 seconds
storage size: 17123343165 Bytes
https://doris-community-test-1308700295.cos.ap-hongkong.myqcloud.com/tmp/20221201101613_clickbench_pr_56172.html
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [doris] morrySnow commented on a diff in pull request #14730: [feature](nereids)merge proj-proj in post process
Posted by GitBox <gi...@apache.org>.
morrySnow commented on code in PR #14730:
URL: https://github.com/apache/doris/pull/14730#discussion_r1036937981
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/MergeProjectPostProcessor.java:
##########
@@ -0,0 +1,60 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you 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
+//
+// http://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 org.apache.doris.nereids.processor.post;
+
+import org.apache.doris.nereids.CascadesContext;
+import org.apache.doris.nereids.rules.rewrite.logical.MergeProjects;
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalProject;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * merge consecutive projects
+ */
+public class MergeProjectPostProcessor extends PlanPostProcessor {
+
+ @Override
+ public PhysicalProject visitPhysicalProject(PhysicalProject<? extends Plan> project, CascadesContext ctx) {
+ Plan child = project.child();
+ child = child.accept(this, ctx);
+ if (child instanceof PhysicalProject) {
+ Map<Expression, Expression> aliasMap = getAliasProjections((PhysicalProject) child);
+ List<NamedExpression> projections = project.getProjects();
+ projections = projections.stream()
+ .map(e -> MergeProjects.ExpressionReplacer.INSTANCE.visit(e, aliasMap))
+ .map(NamedExpression.class::cast)
+ .collect(Collectors.toList());
+ return project.withProjectionsAndChild(projections, child.child(0));
+ }
+ return project;
Review Comment:
could we abstract a function for merging project list? this function looks like
```
List< NamedExpression> func(List< NamedExpression> top, List< NamedExpression> bottom)
```
and then both merge logical and physical project to call it to do merge job
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/MergeProjects.java:
##########
@@ -92,7 +95,7 @@ public Expression visit(Expression expr, Map<Expression, Expression> substitutio
Slot ref = ((SlotReference) expr).withQualifier(Collections.emptyList());
if (substitutionMap.containsKey(ref)) {
Alias res = (Alias) substitutionMap.get(ref);
- return res.child();
+ return new Alias(res.child(), ref.getName());
Review Comment:
the new Alias is useless and will intro more complexity to expression process. because when we come here the slot is not the root of this expr tree.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org