morrySnow commented on code in PR #14490:
URL: https://github.com/apache/doris/pull/14490#discussion_r1032136253


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java:
##########
@@ -1246,4 +1318,44 @@ private List<Integer> getSlotIdList(TupleDescriptor 
tupleDescriptor) {
                 .map(slot -> slot.getId().asInt())
                 .collect(ImmutableList.toImmutableList());
     }
+
+    private boolean isUnnecessaryProject(PhysicalProject project) {
+        // The project list for agg is always needed,since tuple of agg 
contains the slots used by group by expr
+        if (project.child() instanceof PhysicalAggregate) {

Review Comment:
   how about
   ```sql
   SELECT c1 AS a1, c2 AS a2 FROM (SELECT c1, COUNT(c3) AS c2 FROM t1 GROUP BY 
c1) t2
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java:
##########
@@ -135,6 +136,13 @@ public PlanFragment translatePlan(PhysicalPlan 
physicalPlan, PlanTranslatorConte
             rootFragment = exchangeToMergeFragment(rootFragment, context);
         }
         List<Expr> outputExprs = Lists.newArrayList();
+        if (physicalPlan instanceof PhysicalProject) {
+            PhysicalProject project = (PhysicalProject) physicalPlan;
+            if (isUnnecessaryProject(project)) {
+                List<Slot> slotReferences = removeAlias(project);
+                physicalPlan = (PhysicalPlan) 
physicalPlan.child(0).withOutput(slotReferences);

Review Comment:
   no need to update child's output.  generate outputExprs according project's 
output's order is enough



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java:
##########
@@ -675,28 +683,53 @@ public PlanFragment visitPhysicalHashJoin(
         if (hashJoin.getOtherJoinConjuncts().isEmpty()
                 && (joinType == JoinType.LEFT_ANTI_JOIN || joinType == 
JoinType.LEFT_SEMI_JOIN)) {
             for (SlotDescriptor leftSlotDescriptor : leftSlotDescriptors) {
+                if (!leftSlotDescriptor.isMaterialized()) {
+                    continue;
+                }
                 SlotReference sf = 
leftChildOutputMap.get(context.findExprId(leftSlotDescriptor.getId()));
+                if (sf == null) {
+                    continue;
+                }

Review Comment:
   add this because we remove project on olapScan? chould we add a method to 
TupleDescriptor to remove slot from tuple descriptor.
   `updateChildSlotsMaterialization` works like remove slot instead of set slot 
to Materialized.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java:
##########
@@ -901,42 +958,57 @@ public PlanFragment 
visitPhysicalProject(PhysicalProject<? extends Plan> project
             }
         }
         PlanFragment inputFragment = project.child(0).accept(this, context);
-
         List<Expr> execExprList = project.getProjects()
                 .stream()
                 .map(e -> ExpressionTranslator.translate(e, context))
                 .collect(Collectors.toList());
         // TODO: fix the project alias of an aliased relation.
-        List<Slot> slotList = project.getOutput();
-        TupleDescriptor tupleDescriptor = generateTupleDesc(slotList, null, 
context);
+
         PlanNode inputPlanNode = inputFragment.getPlanRoot();
+        List<Slot> slotList = project.getOutput();
+        if (!hasExprCalc(project)) {
+            List<NamedExpression> namedExpressions = project.getProjects();
+            for (int i = 0; i < namedExpressions.size(); i++) {
+                NamedExpression n = namedExpressions.get(i);
+                for (Expression e : n.children()) {
+                    SlotReference slotReference = (SlotReference) e;
+                    SlotRef slotRef = 
context.findSlotRef(slotReference.getExprId());
+                    context.addExprIdSlotRefPair(slotList.get(i).getExprId(), 
slotRef);
+                }
+            }
+        } else {
+            if (!(inputPlanNode instanceof OlapScanNode && 
!hasExprCalc(project))) {
+                TupleDescriptor tupleDescriptor = generateTupleDesc(slotList, 
null, context);
+                inputPlanNode.setProjectList(execExprList);
+                inputPlanNode.setOutputTupleDesc(tupleDescriptor);
+            }
+        }
         // For hash join node, use vSrcToOutputSMap to describe the expression 
calculation, use
         // vIntermediateTupleDescList as input, and set vOutputTupleDesc as 
the final output.
         // TODO: HashJoinNode's be implementation is not support projection 
yet, remove this after when supported.
         if (inputPlanNode instanceof HashJoinNode) {

Review Comment:
   use `inputPlanNode instanceOf JoinNodeBase` to merge two join if statement



-- 
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-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to