diff --git a/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md index 36152eef73..cf21b31a74 100644 --- a/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md +++ b/docs/en/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md @@ -176,6 +176,8 @@ otherwise, an error "Unable to find a suitable base table for partitioning" will - If window functions are used, the partition column fields must be after the PARTITION BY. - Data changes should occur on partitioned tables. If they occur on non-partitioned tables, the materialized view needs to be fully rebuilt. - Using the fields that generate nulls in the JOIN as partition fields in the materialized view prohibits partition incremental updates. +- The base table partition table referenced by the materialized view currently only supports internal tables and HIVE tables. The attribute of the partition column of the inner table cannot be NULL. The HIVE table allows NULL. + #### property The materialized view can specify both the properties of the table and the properties unique to the materialized view. diff --git a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md index 7a616d3848..658ca00115 100644 --- a/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md +++ b/docs/zh-CN/docs/sql-manual/sql-reference/Data-Definition-Statements/Create/CREATE-ASYNC-MATERIALIZED-VIEW.md @@ -174,6 +174,7 @@ KEY(k1,k2) - 如果使用了 window 函数,分区列的字段一定要在partition by后。 - 数据变更应发生在分区表上,如果发生在非分区表,物化视图需要全量构建。 - 物化视图使用 Join 的 null 产生端的字段作为分区字段,不能分区增量更新。 +- 物化视图引用的 base table 分区表,目前只支持内表和 HIVE 表。其中内表的分区列的属性不能是 NULL。HIVE表允许为 NULL。 #### property 物化视图既可以指定table的property,也可以指定物化视图特有的property。 diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVCache.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVCache.java index 94076563ee..c737085bec 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVCache.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVCache.java @@ -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() { + @Override + public Plan visit(Plan plan, Object context) { + if (plan instanceof LogicalResultSink) { + return ((LogicalResultSink) plan).child(); + } + return super.visit(plan, context); + } + }, null); + return new MTMVCache(mvPlan, originPlan); } }