This is an automated email from the ASF dual-hosted git repository.
yujun777 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new a0152451091 [fix](ivm) Fall back to regular MVs when stream
prerequisites are missing (#70799)
a0152451091 is described below
commit a0152451091aaae2c482bb17231f85f6770f6d97
Author: yujun <[email protected]>
AuthorDate: Mon Nov 23 14:23:41 2026 +0800
[fix](ivm) Fall back to regular MVs when stream prerequisites are missing
(#70799)
### Background
Doris uses `REFRESH AUTO` by default for asynchronous materialized
views. During creation, AUTO probes whether the view can use incremental
view maintenance (IVM). IVM reads base table changes through internal
table streams.
### What problem does this PR solve?
Issue Number: None
Related PR: #62606 (introduced the IVM CREATE probe)
PR Type: Bugfix
Problem Summary:
Creating an asynchronous materialized view over a changelog-enabled
table could fail when the FE stream switch was disabled or a
merge-on-write base table had no historical changelog values. For
example, `CREATE MATERIALIZED VIEW mv BUILD DEFERRED AS SELECT k, SUM(v)
FROM t GROUP BY k` could reach Stream creation and fail after the IVM
view was registered. AUTO now creates a regular asynchronous
materialized view in either case.
### Details
- **Frequency:** Always when IVM query analysis succeeds and a required
stream fails either prerequisite.
- **Root cause:** `CreateMTMVInfo` only retried regular MV analysis when
the IVM query probe failed. The catalog checked Stream availability
after the IVM schema was already registered.
- **Why existing tests missed it:** `CreateMTMVCommandTest` enabled
table streams in class setup, and its prior AUTO fallback tests
exercised query analysis errors. `test_ivm_basic_mtmv` exercises
explicit incremental refresh with the required changelog history
enabled.
- **Fix:** Reuse the catalog's Stream enablement and base table checks
during IVM CREATE analysis. Skip excluded base tables and existing
targets of `IF NOT EXISTS`. Restore the original MV properties before
retrying regular analysis.
- **Other paths and branches:** Both deployment modes share this FE
precheck. Stream DDL still validates the live state when it provisions
streams. The AUTO IVM probe is absent from the upstream 3.1, 4.0, 4.1,
and 4.2 branches.
- **Behavior change:** AUTO reports the qualified materialized view name
and the fallback reason in the FE log. Explicit INCREMENTAL reports
missing Stream prerequisites during analysis.
---
.../apache/doris/datasource/InternalCatalog.java | 6 ++-
.../java/org/apache/doris/mtmv/ivm/IvmUtil.java | 3 ++
.../trees/plans/commands/CreateMTMVCommand.java | 10 ++--
.../trees/plans/commands/info/CreateMTMVInfo.java | 44 ++++++++++++++-
.../nereids/trees/plans/CreateMTMVCommandTest.java | 62 +++++++++++++++++++++-
5 files changed, 115 insertions(+), 10 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
index 1d654066324..1b539ddd678 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
@@ -4239,11 +4239,15 @@ public class InternalCatalog implements
CatalogIf<Database> {
Env.getCurrentEnv().getRefreshManager().removeFromRefreshMap(getId());
}
- public void createTableStream(CreateStreamCommand command) throws
DdlException {
+ public static void checkTableStreamEnabled() throws DdlException {
if (!Config.enable_table_stream) {
throw new DdlException("Table Stream is experimental."
+ " Please set enable_table_stream=true to enable it.");
}
+ }
+
+ public void createTableStream(CreateStreamCommand command) throws
DdlException {
+ checkTableStreamEnabled();
CreateStreamInfo createStreamInfo = command.getCreateStreamInfo();
String dbName = createStreamInfo.getStreamName().getDb();
String streamName = createStreamInfo.getStreamName().getTbl();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmUtil.java
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmUtil.java
index a6bcb7247ce..5b84ca7d6f5 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmUtil.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmUtil.java
@@ -24,6 +24,7 @@ import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.info.TableNameInfo;
import org.apache.doris.catalog.stream.BaseTableStream;
+import org.apache.doris.catalog.stream.BaseTableStream.StreamScanType;
import org.apache.doris.catalog.stream.OlapTableStream;
import org.apache.doris.common.util.DebugPointUtil;
import org.apache.doris.datasource.InternalCatalog;
@@ -67,6 +68,8 @@ import java.util.Set;
* Column name constants are defined in {@link Column}.
*/
public class IvmUtil {
+ public static final StreamScanType IVM_STREAM_SCAN_TYPE =
StreamScanType.MIN_DELTA;
+
// Exceptional hidden-column defaults. Numeric and string-like hidden
columns use zero and
// empty string by default; add an entry here only when a hidden column
requires a different
// value.
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateMTMVCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateMTMVCommand.java
index b799ae3edb7..979d1a839a9 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateMTMVCommand.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateMTMVCommand.java
@@ -26,7 +26,6 @@ import org.apache.doris.catalog.Table;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.info.TableNameInfo;
import org.apache.doris.catalog.stream.BaseTableStream;
-import org.apache.doris.catalog.stream.BaseTableStream.StreamScanType;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.UserException;
import org.apache.doris.common.util.PropertyAnalyzer;
@@ -49,6 +48,7 @@ import org.apache.logging.log4j.Logger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
@@ -91,7 +91,7 @@ public class CreateMTMVCommand extends Command implements
ForwardWithSync {
}
/**
- * If the MTMV enables IVM (explicit INCREMENTAL refresh), automatically
+ * If the MTMV enables IVM, automatically
* creates a stream for each base table so the delta rewrite path can
* read changelog data through the existing stream scan infrastructure.
*/
@@ -189,10 +189,8 @@ public class CreateMTMVCommand extends Command implements
ForwardWithSync {
}
Map<String, String> streamProps = new HashMap<>();
streamProps.put(PropertyAnalyzer.PROPERTIES_STREAM_SHOW_INITIAL_ROWS, "true");
- if (baseTable instanceof OlapTable && ((OlapTable)
baseTable).isUniqKeyMergeOnWrite()) {
- streamProps.put(PropertyAnalyzer.PROPERTIES_STREAM_TYPE,
- StreamScanType.MIN_DELTA.name().toLowerCase());
- }
+ streamProps.put(PropertyAnalyzer.PROPERTIES_STREAM_TYPE,
+
IvmUtil.IVM_STREAM_SCAN_TYPE.name().toLowerCase(Locale.ROOT));
CreateStreamInfo streamInfo = new CreateStreamInfo(
false /* ifNotExists */, false /* orReplace */,
streamTableName, baseTableName,
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java
index 98bce5a233e..6f3a4a93a82 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateMTMVInfo.java
@@ -25,7 +25,9 @@ import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.KeysType;
import org.apache.doris.catalog.PartitionType;
+import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.info.TableNameInfo;
+import org.apache.doris.common.DdlException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.FeConstants;
@@ -40,6 +42,7 @@ import org.apache.doris.datasource.mvcc.MvccSnapshot;
import org.apache.doris.datasource.mvcc.MvccTableInfo;
import org.apache.doris.datasource.mvcc.MvccUtil;
import org.apache.doris.datasource.mvcc.PluginDrivenMvccExternalTable;
+import org.apache.doris.mtmv.BaseTableInfo;
import org.apache.doris.mtmv.MTMVAnalyzeQueryInfo;
import org.apache.doris.mtmv.MTMVPartitionInfo;
import org.apache.doris.mtmv.MTMVPartitionInfo.MTMVPartitionType;
@@ -54,6 +57,7 @@ import org.apache.doris.mtmv.MTMVUtil;
import org.apache.doris.mtmv.ivm.IvmException;
import org.apache.doris.mtmv.ivm.IvmFailureReason;
import org.apache.doris.mtmv.ivm.IvmRewriteContext;
+import org.apache.doris.mtmv.ivm.IvmUtil;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.nereids.CascadesContext;
import org.apache.doris.nereids.StatementContext;
@@ -282,8 +286,8 @@ public class CreateMTMVInfo extends CreateTableInfo {
// IVM rewrite changes the plan shape. Treat those as probe
failures too: restore the original create
// state and retry regular MTMV analysis. If the regular path also
fails, that error is still returned
// to the user. Explicit INCREMENTAL does not call this helper, so
its strict failure semantics remain.
- LOG.info("AUTO refresh materialized view {} fallback to non-IVM
after IVM probe failed: {}",
- tableNameInfo.getTbl(), e.getMessage());
+ LOG.info("REFRESH AUTO for {}: IVM probe failed, retrying as a
regular asynchronous materialized view: {}",
+ tableNameInfo.toSql(), e.getMessage());
origin.restore(this);
logicalQuery = parseFreshLogicalQuery();
resetStatementContext(ctx);
@@ -363,6 +367,9 @@ public class CreateMTMVInfo extends CreateTableInfo {
this.mvPartitionDefinition, this.distribution,
this.simpleColumnDefinitions, this.properties, this.keys,
this.logicalQuery, isEnableIvm() ?
Optional.of(IvmRewriteContext.create(tableNameInfo.getTbl()))
: Optional.empty());
+ if (isEnableIvm()) {
+ validateIvmStreamPrerequisites(mtmvAnalyzeQueryInfo.getRelation());
+ }
this.mvPartitionInfo = mtmvAnalyzeQueryInfo.getMvPartitionInfo();
this.columns = mtmvAnalyzeQueryInfo.getColumnDefinitions();
this.keys = Utils.copyRequiredList(mtmvAnalyzeQueryInfo.getKeys());
@@ -379,6 +386,36 @@ public class CreateMTMVInfo extends CreateTableInfo {
}
}
+ private void validateIvmStreamPrerequisites(MTMVRelation relation)
+ throws org.apache.doris.common.AnalysisException {
+ // CREATE IF NOT EXISTS skips stream creation when the name is already
registered.
+ if (isIfNotExists() &&
Env.getCurrentInternalCatalog().getDb(tableNameInfo.getDb())
+ .map(db ->
db.isTableExist(tableNameInfo.getTbl())).orElse(false)) {
+ return;
+ }
+ Set<TableNameInfo> excludedTables =
MTMVPropertyUtil.parseTableNameInfos(
+
mvProperties.get(PropertyAnalyzer.PROPERTIES_EXCLUDED_TRIGGER_TABLES));
+ try {
+ for (BaseTableInfo base : relation.getBaseTables()) {
+ if (MTMVPartitionUtil.isTableExcluded(excludedTables,
+ new TableNameInfo(base.getCtlName(), base.getDbName(),
base.getTableName()))) {
+ continue;
+ }
+ InternalCatalog.checkTableStreamEnabled();
+ TableIf table = MTMVUtil.getTable(base);
+ table.readLock();
+ try {
+
table.checkAsTableStreamBaseTable(IvmUtil.IVM_STREAM_SCAN_TYPE);
+ } finally {
+ table.readUnlock();
+ }
+ }
+ } catch (DdlException e) {
+ // Let CREATE with AUTO retry regular MTMV analysis before any
table or stream is created.
+ throw new AnalysisException(e.getMessage(), e);
+ }
+ }
+
private void checkUserSpecifiedKeysForIvm() {
if (isEnableIvm() &&
keys.stream().anyMatch(Column.IVM_ROW_ID_COL::equalsIgnoreCase)) {
throw new IvmException(IvmFailureReason.PLAN_PATTERN_UNSUPPORTED,
@@ -577,6 +614,7 @@ public class CreateMTMVInfo extends CreateTableInfo {
private static class AnalyzeQueryState {
private final Map<String, String> properties;
+ private final Map<String, String> mvProperties;
private final List<ColumnDefinition> columns;
private final List<String> keys;
private final DistributionDescriptor distribution;
@@ -590,6 +628,7 @@ public class CreateMTMVInfo extends CreateTableInfo {
private AnalyzeQueryState(CreateMTMVInfo info) {
this.properties = info.properties == null ? null :
Maps.newHashMap(info.properties);
+ this.mvProperties = Maps.newHashMap(info.mvProperties);
this.columns = info.columns;
this.keys = Utils.copyRequiredList(info.keys);
this.distribution = info.distribution;
@@ -608,6 +647,7 @@ public class CreateMTMVInfo extends CreateTableInfo {
private void restore(CreateMTMVInfo info) {
info.properties = properties == null ? null :
Maps.newHashMap(properties);
+ info.mvProperties = Maps.newHashMap(mvProperties);
info.columns = columns;
info.keys = Utils.copyRequiredList(keys);
info.distribution = distribution;
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/CreateMTMVCommandTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/CreateMTMVCommandTest.java
index d24dee0dc19..ec891306957 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/CreateMTMVCommandTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/CreateMTMVCommandTest.java
@@ -65,13 +65,21 @@ import java.util.Map;
import java.util.stream.Collectors;
public class CreateMTMVCommandTest extends TestWithFeService {
+ private boolean originalEnableTableStream;
+
@Override
protected void runBeforeAll() throws Exception {
+ originalEnableTableStream = Config.enable_table_stream;
createDatabase("test");
connectContext.setDatabase("test");
Config.enable_table_stream = true;
}
+ @Override
+ protected void runAfterAll() {
+ Config.enable_table_stream = originalEnableTableStream;
+ }
+
@Override
public void createTable(String sql) throws Exception {
boolean originalEnableFeatureChangelog =
Config.enable_feature_changelog;
@@ -535,6 +543,58 @@ public class CreateMTMVCommandTest extends
TestWithFeService {
Assertions.assertTrue(mtmv.getIvmInfo().isEnableIvm());
}
+ @Test
+ public void testCreateAutoMTMVFallsBackWhenTableStreamsAreDisabled()
throws Exception {
+ createIvmMowTable("mtmv_auto_stream_disabled_base");
+ boolean previousEnableTableStream = Config.enable_table_stream;
+ try {
+ Config.enable_table_stream = false;
+ createMtmv("CREATE MATERIALIZED VIEW mtmv_auto_stream_disabled
BUILD DEFERRED\n"
+ + " PROPERTIES ('replication_num' = '1')\n"
+ + " AS SELECT k1, SUM(v1) AS s FROM
mtmv_auto_stream_disabled_base GROUP BY k1;");
+
+ MTMV mtmv = getMtmv("mtmv_auto_stream_disabled");
+ Assertions.assertEquals(RefreshMethod.AUTO,
mtmv.getRefreshInfo().getRefreshMethod());
+ Assertions.assertFalse(mtmv.isIvm());
+ Assertions.assertNull(mtmv.getColumn(Column.IVM_ROW_ID_COL));
+ assertCreateMtmvFails("CREATE MATERIALIZED VIEW
mtmv_incr_stream_disabled\n"
+ + " BUILD DEFERRED REFRESH INCREMENTAL ON MANUAL\n"
+ + " PROPERTIES ('replication_num' = '1')\n"
+ + " AS SELECT k1, SUM(v1) AS s FROM
mtmv_auto_stream_disabled_base GROUP BY k1;",
+ "enable_table_stream=true");
+
+ createMtmv("CREATE MATERIALIZED VIEW IF NOT EXISTS
mtmv_auto_stream_disabled\n"
+ + " BUILD DEFERRED REFRESH INCREMENTAL ON MANUAL\n"
+ + " PROPERTIES ('replication_num' = '1')\n"
+ + " AS SELECT k1, SUM(v1) AS s FROM
mtmv_auto_stream_disabled_base GROUP BY k1;");
+ Assertions.assertSame(mtmv, getMtmv("mtmv_auto_stream_disabled"));
+ } finally {
+ Config.enable_table_stream = previousEnableTableStream;
+ }
+ }
+
+ @Test
+ public void
testCreateAutoMTMVFallsBackWhenHistoricalChangelogValuesAreDisabled() throws
Exception {
+ createTable("CREATE TABLE test.mtmv_auto_no_history_base (k1 INT, v1
INT)\n"
+ + " UNIQUE KEY(k1) DISTRIBUTED BY HASH(k1) BUCKETS 1\n"
+ + " PROPERTIES ('replication_num' = '1',
'enable_unique_key_merge_on_write' = 'true',\n"
+ + " 'changelog.enable' = 'true',
'changelog.need_historical_value' = 'false');");
+ createMtmv("CREATE MATERIALIZED VIEW mtmv_auto_no_history\n"
+ + " BUILD DEFERRED REFRESH AUTO ON MANUAL\n"
+ + " PROPERTIES ('replication_num' = '1')\n"
+ + " AS SELECT k1, MIN(v1) AS v FROM mtmv_auto_no_history_base
GROUP BY k1;");
+
+ MTMV mtmv = getMtmv("mtmv_auto_no_history");
+ Assertions.assertFalse(mtmv.isIvm());
+ Assertions.assertNull(mtmv.getColumn(Column.IVM_ROW_ID_COL));
+
Assertions.assertFalse(mtmv.getMvProperties().containsKey(PropertyAnalyzer.PROPERTIES_IVM_MINMAX_TOPK));
+ assertCreateMtmvFails("CREATE MATERIALIZED VIEW mtmv_incr_no_history\n"
+ + " BUILD DEFERRED REFRESH INCREMENTAL FALLBACK ON MANUAL\n"
+ + " PROPERTIES ('replication_num' = '1')\n"
+ + " AS SELECT k1, MIN(v1) AS v FROM mtmv_auto_no_history_base
GROUP BY k1;",
+ "changelog.need_historical_value=true");
+ }
+
@Test
public void testCreateAutoMTMVFallsBackToNonIvmOnIvmException() throws
Exception {
createTable("create table test.mtmv_auto_fallback_agg_base (k1 int, v1
int SUM)\n"
@@ -2358,7 +2418,7 @@ public class CreateMTMVCommandTest extends
TestWithFeService {
+ "unique key(k1)\n"
+ "distributed by hash(k1) buckets 1\n"
+ "properties('replication_num' = '1',
'enable_unique_key_merge_on_write' = 'true', "
- + "'changelog.enable' = 'true',
'changelog.need_historical_value' = 'true');");
+ + "'changelog.enable' = 'true',
'changelog.need_historical_value' = 'false');");
createMtmv("CREATE MATERIALIZED VIEW ivm_excl_stream_mv\n"
+ " BUILD DEFERRED REFRESH INCREMENTAL ON MANUAL\n"
+ " DISTRIBUTED BY RANDOM BUCKETS 2\n"
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]