924060929 commented on code in PR #32047:
URL: https://github.com/apache/doris/pull/32047#discussion_r1522451996


##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVCache.java:
##########
@@ -54,18 +55,22 @@ public Plan getOriginalPlan() {
 
     public static MTMVCache from(MTMV mtmv, ConnectContext connectContext) {
         LogicalPlan unboundMvPlan = new 
NereidsParser().parseSingle(mtmv.getQuerySql());
-        // this will be removed in the future when support join derivation
-        
connectContext.getSessionVariable().setDisableNereidsRules("INFER_PREDICATES, 
ELIMINATE_OUTER_JOIN");
         StatementContext mvSqlStatementContext = new 
StatementContext(connectContext,
                 new OriginStatement(mtmv.getQuerySql(), 0));
         NereidsPlanner planner = new NereidsPlanner(mvSqlStatementContext);
         if (mvSqlStatementContext.getConnectContext().getStatementContext() == 
null) {
             
mvSqlStatementContext.getConnectContext().setStatementContext(mvSqlStatementContext);
         }
-        Plan mvRewrittenPlan = planner.plan(unboundMvPlan, 
PhysicalProperties.ANY, ExplainLevel.REWRITTEN_PLAN);
-        // TODO: should use visitor or a new rule to remove result sink node
-        Plan mvPlan = mvRewrittenPlan instanceof LogicalResultSink
-                ? (Plan) ((LogicalResultSink) mvRewrittenPlan).child() : 
mvRewrittenPlan;
-        return new MTMVCache(mvPlan, mvRewrittenPlan);
+        Plan originPlan = planner.plan(unboundMvPlan, PhysicalProperties.ANY, 
ExplainLevel.REWRITTEN_PLAN);
+        Plan mvPlan = originPlan.accept(new DefaultPlanRewriter<Object>() {
+            @Override
+            public Plan visit(Plan plan, Object context) {
+                if (plan instanceof LogicalResultSink) {
+                    return ((LogicalResultSink<Plan>) plan).child();
+                }
+                return super.visit(plan, context);
+            }
+        }, null);

Review Comment:
   minor:
   alternative 1:
   ```java
   new DefaultPlanRewriter<Object>() {
               @Override
               public Plan visitLogicalResultSink(LogicalResultSink sink, 
Object context) {
                   return plan.child().accept(this, context);
               }
           }
   ```
   
   alternative 2:
   ```java
   Plan mvPlan = originPlan.rewriteUp(p -> p instanceof LogicalResultSink ? 
p.child(0) : p)
   ```



-- 
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