[improvement](mtmv) Remove useless code and add some doc (#32047)
1. Use visitor to remove the result sink in mv plan 2. Remove useless code 3. Add more doc
This commit is contained in:
@ -26,6 +26,7 @@ import org.apache.doris.nereids.trees.plans.Plan;
|
||||
import org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalResultSink;
|
||||
import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanRewriter;
|
||||
import org.apache.doris.qe.ConnectContext;
|
||||
import org.apache.doris.qe.OriginStatement;
|
||||
|
||||
@ -54,18 +55,22 @@ public class MTMVCache {
|
||||
|
||||
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);
|
||||
return new MTMVCache(mvPlan, originPlan);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user