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 ba088a6297e [fix](ivm) Check layout signatures during partition 
refresh (#70839)
ba088a6297e is described below

commit ba088a6297eaf05aea9ccc6afe3869914ea36dda
Author: yujun <[email protected]>
AuthorDate: Mon Nov 23 12:29:48 2026 +0800

    [fix](ivm) Check layout signatures during partition refresh (#70839)
    
    ### Background
    
    A merge-on-write incremental materialized view stores a signature of its
    normalized write plan. The signature protects row identity and aggregate
    state layout across refreshes. A partition refresh rebuilds a subset of
    the view from its base tables.
    
    ### What problem does this PR solve?
    
    Issue Number: None
    Related PR: #70785 (establishes the signature on the first successful
    write)
    PR Type: Bugfix
    
    Problem Summary:
    
    A partition refresh could write a different layout into part of a view
    while other partitions retained the stored layout. Compare the signature
    before each partition write. A strict refresh reports a mismatch and a
    request that allows fallback runs a whole-view COMPLETE.
    
    ```sql
    REFRESH MATERIALIZED VIEW ivm_part_sig_mv PARTITIONS;
    ```
    
    | With a changed signature | Task result |
    | --- | --- |
    | Before | `SUCCESS` with a partial refresh |
    | After | `FAILED` with `IVM layout signature mismatch` |
    
    ### Details
    
    - **Change map:** The FE changes add 90 and remove 45 lines. The FE and
    regression tests add 141 and remove 31 lines, plus 28 generated result
    lines.
    - **Frequency:** Always when a MOW IVM partition rebuild has work to do
    and generates a signature different from the stored one.
    - **Root cause:** `MTMVTask` used the full refresh rewrite mode for
    partition rebuilds. `IvmNormalizeUniqKeysMTMV` compared signatures for
    incremental writes, and the full mode only generated a candidate
    signature.
    - **Why existing tests missed it:** The normalizer unit tests and
    `test_ivm_plan_signature_fallback` checked signature changes on the
    incremental write path. The partition rebuild regressions kept the
    layout fixed.
    - **Fix:** Select PARTITIONS or COMPLETE by the actual refresh scope for
    both IVM table models. Keep the shared stream rewrite and do the
    stored-signature check in the MOW normalizer, including for dirty
    partitions rebuilt before INCREMENTAL. Expose mode predicates through
    the context. When the stored signature is unset, the first successful
    write establishes it.
    - **Other paths and branches:** COMPLETE still checks its own batch
    signatures for consistency and can replace the baseline on success.
    Append-only DUP and ordinary materialized views keep their existing
    refresh paths. This change follows the signature lifecycle in #70785 on
    master.
    - **Behavior change:** Strict partition rebuilds fail before writing a
    mismatching batch. Fallback-enabled requests rebuild the whole view and
    publish its new signature on success.
---
 .../apache/doris/job/extensions/mtmv/MTMVTask.java | 41 +++++++---
 .../java/org/apache/doris/mtmv/MTMVPlanUtil.java   |  2 +-
 .../doris/mtmv/ivm/IvmFailureClassifier.java       |  4 +
 .../doris/mtmv/ivm/IvmNormalizeUniqKeysMTMV.java   | 14 ++--
 .../apache/doris/mtmv/ivm/IvmRewriteContext.java   | 58 ++++++++++----
 .../nereids/rules/analysis/CollectRelation.java    |  5 +-
 .../nereids/rules/analysis/IvmFullRefreshMTMV.java |  2 +-
 .../nereids/rules/analysis/IvmIncrRefreshMTMV.java |  2 +-
 .../nereids/rules/analysis/IvmNormalizeMTMV.java   |  5 +-
 .../trees/plans/commands/RefreshMTMVCommand.java   |  2 +-
 .../org/apache/doris/mtmv/MTMVPlanUtilTest.java    |  9 +--
 .../mtmv/ivm/IvmNormalizeUniqKeysMTMVTest.java     | 20 +++++
 .../doris/mtmv/ivm/IvmRewriteContextTest.java      | 14 ++--
 .../analysis/CollectRelationChangelogTtlTest.java  |  4 +-
 .../rules/analysis/IvmFullRefreshMTMVTest.java     | 10 +--
 .../nereids/trees/plans/CreateMTMVCommandTest.java |  4 +-
 .../commands/UpdateMvByPartitionCommandTest.java   | 18 ++---
 .../ivm/test_ivm_partition_signature_fallback.out  | 28 +++++++
 .../test_ivm_partition_signature_fallback.groovy   | 93 ++++++++++++++++++++++
 19 files changed, 259 insertions(+), 76 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java 
b/fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java
index 5460388ff8f..9bad81fb20f 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java
@@ -907,11 +907,8 @@ public class MTMVTask extends AbstractTask {
             try {
                 executePartitionBasedRefresh(refreshContext, 
RefreshMode.PARTITIONS, ctx, toRebuild);
             } catch (JobException e) {
-                // The rebuild reads the tables the MV does not partition by 
through their streams at the
-                // offsets, so an offset changelog.ttl_seconds has expired 
stops it the way it stops the delta
-                // below. Only a failure whose one repair is COMPLETE becomes 
a fallback here: the rebuild already
-                // is the partition refresh, and the sync-and-retry the delta 
has for a missing MV partition does
-                // not exist on this path. Any other failure still fails the 
attempt.
+                // The partition rebuild can encounter an expired stream 
offset or an incompatible layout.
+                // Both require a whole-MV rebuild. Other failures still fail 
the attempt.
                 String detail = Util.getRootCauseMessage(e);
                 Optional<IvmFailureReason> reason = 
IvmFailureClassifier.classifyExecutionFailure(detail)
                         .filter(IvmFailureReason::requiresCompleteRefresh);
@@ -1344,9 +1341,28 @@ public class MTMVTask extends AbstractTask {
         if (refreshMode == MTMVTaskRefreshMode.NOT_REFRESH) {
             return true;
         }
-        executePartitionBasedRefresh(partitionPlan.context, 
RefreshMode.PARTITIONS, ctx,
-                partitionPlan.partitions);
-        return true;
+        try {
+            executePartitionBasedRefresh(partitionPlan.context, 
RefreshMode.PARTITIONS, ctx,
+                    partitionPlan.partitions);
+            return true;
+        } catch (JobException e) {
+            Optional<IvmFailureReason> reason = 
IvmFailureClassifier.classifyExecutionFailure(
+                    Util.getRootCauseMessage(e))
+                    .filter(candidate -> candidate == 
IvmFailureReason.PLAN_SIGNATURE_MISMATCH);
+            if (reason.isEmpty()) {
+                throw e;
+            }
+            String reasonName = reason.get().name();
+            if (!request.allowFallback) {
+                failureStage = reasonName;
+                throw e;
+            }
+            ivmFallbackReason = reasonName;
+            fallingBack = true;
+            LOG.warn("IVM partition refresh signature mismatch for mv={}, 
taskId={}. Continuing with COMPLETE refresh.",
+                    mtmv.getName(), getTaskId());
+            return false;
+        }
     }
 
     private void executePartitionBasedRefresh(MTMVRefreshContext context, 
RefreshMode refreshMode,
@@ -1386,7 +1402,7 @@ public class MTMVTask extends AbstractTask {
         boolean refreshAllPartitions = 
Sets.newHashSet(partitions).equals(mtmv.getPartitionNames());
         // A whole-MV COMPLETE resets the stream baselines as it rebuilds the 
rows. Publish the
         // matching layout signature with that successful baseline, including 
a capacity change.
-        boolean replacePlanSignature = refreshMode == RefreshMode.COMPLETE && 
mtmv.isIvm()
+        boolean replacePlanSignature = refreshMode == RefreshMode.COMPLETE && 
useIvmFallbackStreams
                 && !mtmv.isIvmAppendOnlyDupTable();
         IvmPlanSignature refreshedPlanSignature = null;
         for (int i = 0; i < execNum; i++) {
@@ -1400,8 +1416,9 @@ public class MTMVTask extends AbstractTask {
             if (useIvmFallbackStreams) {
                 StreamReadMode nonPctReadMode = i == 0 && refreshAllPartitions
                         ? StreamReadMode.RESET : StreamReadMode.SNAPSHOT;
-                rewriteContext = Optional.of(
-                        IvmRewriteContext.full(mtmv, batchResetPartitionIds, 
nonPctReadMode));
+                rewriteContext = Optional.of(refreshMode == 
RefreshMode.PARTITIONS
+                        ? IvmRewriteContext.partitions(mtmv, 
batchResetPartitionIds, nonPctReadMode)
+                        : IvmRewriteContext.complete(mtmv, 
batchResetPartitionIds, nonPctReadMode));
             }
             // The requirement this batch is read under, captured before the 
read below and recorded once
             // the read's data has committed, next to its snapshots. Capturing 
it per batch keeps an
@@ -1529,7 +1546,7 @@ public class MTMVTask extends AbstractTask {
             pctTableInfos.add(pctInfo.getTableInfo());
         }
         // Every table of the plan that is not a PCT table is read through its 
stream: the partition
-        // refresh gives those tables a read mode (IvmRewriteContext.full).
+        // refresh gives those tables a read mode 
(IvmRewriteContext.partitions).
         for (BaseTableInfo baseTableInfo : 
relation.getBaseTablesOneLevelAndFromView()) {
             if (pctTableInfos.contains(baseTableInfo)) {
                 continue;
diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java 
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java
index 0079bcc118b..591cd46517d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java
@@ -675,7 +675,7 @@ public class MTMVPlanUtil {
             // must not mutate it here (the change would bypass journaling).
             ivmRewriteContext.ifPresent(rewriteContext -> {
                 Long resolved = rewriteContext.getResolvedMinMaxTopK();
-                if (rewriteContext.getMode() == IvmRewriteContext.Mode.CREATE 
&& resolved != null
+                if (rewriteContext.isCreate() && resolved != null
                         && 
!mvProperties.containsKey(PropertyAnalyzer.PROPERTIES_IVM_MINMAX_TOPK)) {
                     
mvProperties.put(PropertyAnalyzer.PROPERTIES_IVM_MINMAX_TOPK, 
String.valueOf(resolved));
                 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmFailureClassifier.java 
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmFailureClassifier.java
index e0c7244ac78..12f9e3c5db6 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmFailureClassifier.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmFailureClassifier.java
@@ -32,12 +32,16 @@ public final class IvmFailureClassifier {
     public static final String NON_DETERMINISTIC_ROW_ID_MSG_PREFIX =
             "IVM fallback: delete on non-deterministic row_id";
     public static final String MV_PARTITION_NOT_FOUND_MSG = "no partition for 
this tuple";
+    public static final String PLAN_SIGNATURE_MISMATCH_MSG_PREFIX = "IVM 
layout signature mismatch for mv=";
 
     private IvmFailureClassifier() {
     }
 
     public static Optional<IvmFailureReason> classifyExecutionFailure(String 
detail) {
         Objects.requireNonNull(detail, "detail can not be null");
+        if (detail.contains(PLAN_SIGNATURE_MISMATCH_MSG_PREFIX)) {
+            return Optional.of(IvmFailureReason.PLAN_SIGNATURE_MISMATCH);
+        }
         if (detail.contains(MIN_MAX_BOUNDARY_MSG_PREFIX)) {
             return Optional.of(IvmFailureReason.MIN_MAX_BOUNDARY_HIT);
         }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmNormalizeUniqKeysMTMV.java
 
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmNormalizeUniqKeysMTMV.java
index 5e0d8412fa0..ba7a6704422 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmNormalizeUniqKeysMTMV.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmNormalizeUniqKeysMTMV.java
@@ -217,7 +217,7 @@ public class IvmNormalizeUniqKeysMTMV extends 
DefaultPlanRewriter<IvmNormalizeUn
 
     /**
      * Normalizes a unique-key MV statement after {@link IvmNormalizeMTMV} 
selects its model.
-     * Computes the layout signature for write plans and checks the existing 
baseline for incremental refresh.
+     * Computes the write plan's signature and checks the existing baseline 
for incremental and partition refresh.
      */
     public Plan normalizeRoot(Plan plan, JobContext jobContext) {
         Plan result = normalize(plan, jobContext);
@@ -231,7 +231,7 @@ public class IvmNormalizeUniqKeysMTMV extends 
DefaultPlanRewriter<IvmNormalizeUn
         }
 
         IvmPlanSignature signature = new 
IvmPlanSignatureGenerator().generate(result);
-        if (ivmRewriteContext.getMode() == IvmRewriteContext.Mode.INCREMENTAL) 
{
+        if (ivmRewriteContext.isIncrementalRefresh() || 
ivmRewriteContext.isPartitionsRefresh()) {
             validatePlanSignature(ivmRewriteContext.getMtmv(), signature);
         }
         rewriteResult.setPlanSignature(signature);
@@ -243,13 +243,12 @@ public class IvmNormalizeUniqKeysMTMV extends 
DefaultPlanRewriter<IvmNormalizeUn
         if (storedSignature == null || 
storedSignature.equals(currentSignature.getSha256())) {
             return;
         }
-        String detail = "IVM layout signature mismatch for mv=" + 
mtmv.getName()
+        String detail = 
IvmFailureClassifier.PLAN_SIGNATURE_MISMATCH_MSG_PREFIX + mtmv.getName()
                 + ", storedSignature=" + storedSignature
                 + ", currentSignature=" + currentSignature.getSha256()
                 + ", currentCanonical=" + currentSignature.getCanonicalString()
                 + ", currentPlan=" + currentSignature.getPlanTree()
-                + ". Run one REFRESH MATERIALIZED VIEW " + mtmv.getName()
-                + " INCREMENTAL FALLBACK or REFRESH MATERIALIZED VIEW " + 
mtmv.getName()
+                + ". Run REFRESH MATERIALIZED VIEW " + mtmv.getName()
                 + " COMPLETE to rebuild the IVM layout baseline and publish 
its matching signature.";
         throw new IvmException(IvmFailureReason.PLAN_SIGNATURE_MISMATCH, 
detail);
     }
@@ -1332,11 +1331,10 @@ public class IvmNormalizeUniqKeysMTMV extends 
DefaultPlanRewriter<IvmNormalizeUn
         // The layout is only defined where the view is created or where an 
incremental refresh reads the
         // old state, and those are the two places this check runs: at CREATE 
it reports early that the
         // layout being defined cannot be maintained incrementally, and on an 
incremental refresh it
-        // reports the state a merge would read. NORMALIZE and FULL only 
re-analyze the layout of an
+        // reports the state a merge would read. NORMALIZE and partition 
rebuilds re-analyze the layout of an
         // existing view, where a state column can be absent for reasons this 
check cannot judge -- the
         // view then still completes a full refresh, which is how such a 
layout is rebuilt.
-        IvmRewriteContext.Mode mode = ivmRewriteContext.getMode();
-        if (mode != IvmRewriteContext.Mode.CREATE && mode != 
IvmRewriteContext.Mode.INCREMENTAL) {
+        if (!ivmRewriteContext.isCreate() && 
!ivmRewriteContext.isIncrementalRefresh()) {
             return;
         }
         Set<String> persistedColumns = normalizedPlan.getOutput().stream()
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmRewriteContext.java 
b/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmRewriteContext.java
index dce4409112c..f4da70aabb7 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmRewriteContext.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/ivm/IvmRewriteContext.java
@@ -34,23 +34,25 @@ import java.util.Set;
  *
  * <p>The context is installed on the statement and selects which IVM path is 
active:
  * create when an IVM materialized view is created, normalize when an IVM 
materialized view is analyzed,
- * incremental when an incremental refresh plan is generated, and full when a 
complete refresh plan uses IVM
- * stream scans.
+ * incremental when an incremental refresh plan is generated, and partitions 
or complete when a rebuild plan
+ * uses IVM stream scans.
  * It contains rewrite configuration, and one thing the rewrite feeds back: 
whether a snapshot read of a
  * table the MV does not partition by answered with the image at the stream 
offset rather than with the
  * table as it is now. A refresh owns one context per statement it runs, so 
that is where the answer
  * reaches it. Per-statement rewrite artifacts proper are stored in {@link 
IvmRewriteResult}.
  */
 public class IvmRewriteContext {
-    public enum Mode {
+    private enum Mode {
         /** Normalize an IVM materialized-view query during CREATE 
MATERIALIZED VIEW. */
         CREATE,
         /** Normalize the materialized-view query and collect its IVM layout 
metadata. */
         NORMALIZE,
         /** Rewrite the normalized query into an incremental refresh delta 
plan. */
         INCREMENTAL,
+        /** Rebuild selected partitions using the MV's existing layout. */
+        PARTITIONS,
         /** Rewrite a complete refresh plan with the IVM full-refresh stream 
semantics. */
-        FULL
+        COMPLETE
     }
 
     /**
@@ -80,7 +82,7 @@ public class IvmRewriteContext {
     private final Optional<StreamReadMode> fullRefreshNonPctReadMode;
     // Base partitions the incremental delta may read, per base table. A table 
that is absent is
     // read in full, so an empty map keeps the unrestricted behaviour. Unlike
-    // fullRefreshResetPartitionIds, which names the partitions a COMPLETE 
refresh must reset,
+    // fullRefreshResetPartitionIds, which names the partitions a 
partition-based refresh must reset,
     // every entry here is an upper bound on what the delta is allowed to read.
     private final Map<BaseTableInfo, Set<Long>> incrementalScopePartitionIds;
     // Set by MTMVPlanUtil before normalization: true means the MV unique keys 
include identity key columns.
@@ -177,35 +179,61 @@ public class IvmRewriteContext {
      * plan the normalized query over ordinary base scans -- a different plan 
from the one the
      * refresh executes.
      */
-    public static IvmRewriteContext fullExplain(MTMV mtmv) {
-        return new IvmRewriteContext(Mode.FULL, Objects.requireNonNull(mtmv, 
"mtmv can not be null"),
+    public static IvmRewriteContext completeExplain(MTMV mtmv) {
+        return new IvmRewriteContext(Mode.COMPLETE, 
Objects.requireNonNull(mtmv, "mtmv can not be null"),
                 null, false, ExecutionKind.EXPLAIN, Optional.empty(), 
Collections.emptyMap(),
                 Optional.of(StreamReadMode.RESET), Collections.emptyMap());
     }
 
-    public static IvmRewriteContext full(MTMV mtmv) {
-        return new IvmRewriteContext(Mode.FULL, Objects.requireNonNull(mtmv, 
"mtmv can not be null"),
+    public static IvmRewriteContext complete(MTMV mtmv) {
+        return new IvmRewriteContext(Mode.COMPLETE, 
Objects.requireNonNull(mtmv, "mtmv can not be null"),
                 null, false, ExecutionKind.EXECUTE, Optional.empty(), 
Collections.emptyMap(), Optional.empty(),
                 Collections.emptyMap());
     }
 
-    public static IvmRewriteContext full(MTMV mtmv,
+    public static IvmRewriteContext complete(MTMV mtmv,
             Map<BaseTableInfo, Set<Long>> resetPartitionIds,
             StreamReadMode nonPctReadMode) {
-        return new IvmRewriteContext(Mode.FULL, mtmv, null, false, 
ExecutionKind.EXECUTE, Optional.empty(),
+        return partitionBased(Mode.COMPLETE, mtmv, resetPartitionIds, 
nonPctReadMode);
+    }
+
+    public static IvmRewriteContext partitions(MTMV mtmv, Map<BaseTableInfo, 
Set<Long>> resetPartitionIds,
+            StreamReadMode nonPctReadMode) {
+        return partitionBased(Mode.PARTITIONS, mtmv, resetPartitionIds, 
nonPctReadMode);
+    }
+
+    private static IvmRewriteContext partitionBased(Mode mode, MTMV mtmv,
+            Map<BaseTableInfo, Set<Long>> resetPartitionIds, StreamReadMode 
nonPctReadMode) {
+        return new IvmRewriteContext(mode, mtmv, null, false, 
ExecutionKind.EXECUTE, Optional.empty(),
                 resetPartitionIds,
                 Optional.of(Objects.requireNonNull(nonPctReadMode, 
"nonPctReadMode can not be null")),
                 Collections.emptyMap());
     }
 
-    public Mode getMode() {
-        return mode;
-    }
-
     public boolean isCreate() {
         return mode == Mode.CREATE;
     }
 
+    public boolean isNormalize() {
+        return mode == Mode.NORMALIZE;
+    }
+
+    public boolean isIncrementalRefresh() {
+        return mode == Mode.INCREMENTAL;
+    }
+
+    public boolean isPartitionsRefresh() {
+        return mode == Mode.PARTITIONS;
+    }
+
+    public boolean isCompleteRefresh() {
+        return mode == Mode.COMPLETE;
+    }
+
+    public boolean isPartitionBasedRefresh() {
+        return isCompleteRefresh() || isPartitionsRefresh();
+    }
+
     public MTMV getMtmv() {
         return mtmv;
     }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CollectRelation.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CollectRelation.java
index ddf72482609..ce04f90a152 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CollectRelation.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/CollectRelation.java
@@ -29,7 +29,6 @@ import org.apache.doris.catalog.stream.StreamReadMode;
 import org.apache.doris.common.Pair;
 import org.apache.doris.datasource.plugin.PluginDrivenExternalTable;
 import org.apache.doris.mtmv.BaseTableInfo;
-import org.apache.doris.mtmv.ivm.IvmRewriteContext;
 import org.apache.doris.nereids.CTEContext;
 import org.apache.doris.nereids.CascadesContext;
 import org.apache.doris.nereids.StatementContext;
@@ -364,8 +363,8 @@ public class CollectRelation implements AnalysisRuleFactory 
{
             // IVM creates stream scans during analysis, after the collector 
has visited ordinary base scans.
             // Full refresh can also reconstruct a non-PCT table at its stream 
snapshot using changelog.
             boolean ivmReadsChangelog = statementContext.getIvmRewriteContext()
-                    .map(context -> context.getMode() == 
IvmRewriteContext.Mode.INCREMENTAL
-                            || context.getMode() == IvmRewriteContext.Mode.FULL
+                    .map(context -> context.isIncrementalRefresh()
+                            || context.isPartitionBasedRefresh()
                             && 
context.getFullRefreshNonPctReadMode().orElse(null) == StreamReadMode.SNAPSHOT)
                     .orElse(false);
             if (((OlapTable) table).hasChangelogTtl()
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/IvmFullRefreshMTMV.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/IvmFullRefreshMTMV.java
index ebbf460967d..8dc33ffa952 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/IvmFullRefreshMTMV.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/IvmFullRefreshMTMV.java
@@ -63,7 +63,7 @@ public class IvmFullRefreshMTMV extends OneRewriteRuleFactory 
{
         return logicalOlapScan()
                 .whenNot(LogicalOlapTableStreamScan.class::isInstance)
                 .when(scan -> 
ConnectContext.get().getStatementContext().getIvmRewriteContext()
-                        .filter(context -> context.getMode() == 
IvmRewriteContext.Mode.FULL)
+                        .filter(IvmRewriteContext::isPartitionBasedRefresh)
                         .filter(IvmRewriteContext::hasFullRefreshStreamScans)
                         .isPresent())
                 .thenApply(ctx -> {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/IvmIncrRefreshMTMV.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/IvmIncrRefreshMTMV.java
index 8278d76c501..367095ad53b 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/IvmIncrRefreshMTMV.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/IvmIncrRefreshMTMV.java
@@ -52,7 +52,7 @@ public class IvmIncrRefreshMTMV implements CustomRewriter {
         StatementContext statementContext = 
jobContext.getCascadesContext().getStatementContext();
         Optional<IvmRewriteContext> rewriteContext = 
statementContext.getIvmRewriteContext();
         if (!rewriteContext.isPresent()
-                || rewriteContext.get().getMode() != 
IvmRewriteContext.Mode.INCREMENTAL) {
+                || !rewriteContext.get().isIncrementalRefresh()) {
             return plan;
         }
         IvmRewriteResult rewriteResult = 
jobContext.getCascadesContext().getIvmRewriteResult()
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/IvmNormalizeMTMV.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/IvmNormalizeMTMV.java
index 0ce366723ff..44ba63b4ac5 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/IvmNormalizeMTMV.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/IvmNormalizeMTMV.java
@@ -83,7 +83,7 @@ public class IvmNormalizeMTMV implements CustomRewriter {
         // that a statement downstream of this rewrite reads the plan of the 
model that was chosen.
         rewriteResult.setNormalizeRewritten(true);
         rewriteResult.setNormalizedPlan(result);
-        if (rewriteContext.getMode() == IvmRewriteContext.Mode.CREATE) {
+        if (rewriteContext.isCreate()) {
             LOG.info("IVM normalized plan, mtmvName={}, keysType={}, 
detailModel={}, inputRoot={}, plan={}",
                     rewriteContext.getMtmvName(), keysType, detailModel, 
plan.getClass().getSimpleName(),
                     result.treeString());
@@ -102,8 +102,7 @@ public class IvmNormalizeMTMV implements CustomRewriter {
             return mtmv.isIvmAppendOnlyDupTable() ? KeysType.DUP_KEYS : 
KeysType.UNIQUE_KEYS;
         }
         Preconditions.checkState(rewriteContext.isCreate(),
-                "an IVM rewrite without an MV can only be CREATE, but its mode 
is: %s",
-                rewriteContext.getMode());
+                "only CREATE can rewrite an IVM query without an MV");
         return judgeKeysType(plan, rewriteContext);
     }
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/RefreshMTMVCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/RefreshMTMVCommand.java
index a728038ca26..525e14e66d3 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/RefreshMTMVCommand.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/RefreshMTMVCommand.java
@@ -234,7 +234,7 @@ public class RefreshMTMVCommand extends Command implements 
Forward, Explainable
                 return createIvmIncrRefreshManager().buildInsertCommand(mtmv);
             case COMPLETE:
                 if (mtmv.isIvm()) {
-                    
statementContext.setIvmRewriteContext(Optional.of(IvmRewriteContext.fullExplain(mtmv)));
+                    
statementContext.setIvmRewriteContext(Optional.of(IvmRewriteContext.completeExplain(mtmv)));
                 }
                 
statementContext.setExcludedTriggerTables(mtmv.getExcludedTriggerTables());
                 return UpdateMvByPartitionCommand.from(
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPlanUtilTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPlanUtilTest.java
index eb629baba9c..01feeea0a9c 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPlanUtilTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPlanUtilTest.java
@@ -427,8 +427,7 @@ public class MTMVPlanUtilTest extends SqlTestBase {
         MTMVPlanUtil.analyzeQuery(connectContext, Maps.newHashMap(), 
mtmvPartitionDefinition,
                 distributionDescriptor, null, Maps.newHashMap(), 
Lists.newArrayList(), logicalPlan,
                 Optional.of(IvmRewriteContext.create("test_mtmv")));
-        Assertions.assertEquals(IvmRewriteContext.Mode.CREATE,
-                
statementContext.getIvmRewriteContext().orElseThrow().getMode());
+        
Assertions.assertTrue(statementContext.getIvmRewriteContext().orElseThrow().isCreate());
     }
 
     @Test
@@ -525,14 +524,12 @@ public class MTMVPlanUtilTest extends SqlTestBase {
         ConnectContext autoCtx = MTMVPlanUtil.createMTMVContext(autoMtmv,
                 MTMVPlanUtil.DISABLE_RULES_WHEN_GENERATE_MTMV_CACHE);
         Assertions.assertDoesNotThrow(() -> 
MTMVPlanUtil.ensureMTMVQueryUsable(autoMtmv, autoCtx));
-        Assertions.assertEquals(IvmRewriteContext.Mode.NORMALIZE,
-                
autoCtx.getStatementContext().getIvmRewriteContext().orElseThrow().getMode());
+        
Assertions.assertTrue(autoCtx.getStatementContext().getIvmRewriteContext().orElseThrow().isNormalize());
 
         ConnectContext incrementalCtx = 
MTMVPlanUtil.createMTMVContext(incrementalMtmv,
                 MTMVPlanUtil.DISABLE_RULES_WHEN_GENERATE_MTMV_CACHE);
         Assertions.assertDoesNotThrow(() -> 
MTMVPlanUtil.ensureMTMVQueryUsable(incrementalMtmv, incrementalCtx));
-        Assertions.assertEquals(IvmRewriteContext.Mode.NORMALIZE,
-                
incrementalCtx.getStatementContext().getIvmRewriteContext().orElseThrow().getMode());
+        
Assertions.assertTrue(incrementalCtx.getStatementContext().getIvmRewriteContext().orElseThrow().isNormalize());
     }
 
     @Test
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/mtmv/ivm/IvmNormalizeUniqKeysMTMVTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/mtmv/ivm/IvmNormalizeUniqKeysMTMVTest.java
index 5fd15e1edb7..2f88e800d13 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/mtmv/ivm/IvmNormalizeUniqKeysMTMVTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/mtmv/ivm/IvmNormalizeUniqKeysMTMVTest.java
@@ -30,6 +30,7 @@ import org.apache.doris.catalog.PartitionInfo;
 import org.apache.doris.catalog.TableProperty;
 import org.apache.doris.catalog.Type;
 import org.apache.doris.catalog.info.TableNameInfo;
+import org.apache.doris.catalog.stream.StreamReadMode;
 import org.apache.doris.common.Pair;
 import org.apache.doris.mtmv.ivm.agg.IvmAggFunctionKind;
 import org.apache.doris.mtmv.ivm.agg.IvmAggMeta;
@@ -170,6 +171,25 @@ class IvmNormalizeUniqKeysMTMVTest {
         Assertions.assertNull(mtmv.getIvmInfo().getPlanSignature());
     }
 
+    @Test
+    void testPartitionRefreshRejectsSignatureDriftButCompleteCanRebuild() {
+        MTMV mtmv = mockIvmMtmv("stored-signature");
+        Plan sink = signatureTestSink(mtmv);
+        JobContext partitions = newJobContextForRoot(sink, true, 
Collections.emptySet(),
+                Optional.of(IvmRewriteContext.partitions(mtmv, 
Collections.emptyMap(), StreamReadMode.SNAPSHOT)));
+
+        assertIvmException(IvmFailureReason.PLAN_SIGNATURE_MISMATCH,
+                () -> new IvmNormalizeUniqKeysMTMV().normalizeRoot(sink, 
partitions));
+        
Assertions.assertNull(partitions.getCascadesContext().getIvmRewriteResult().orElseThrow()
+                .getPlanSignature());
+
+        JobContext complete = newJobContextForRoot(sink, true, 
Collections.emptySet(),
+                Optional.of(IvmRewriteContext.complete(mtmv)));
+        new IvmNormalizeUniqKeysMTMV().normalizeRoot(sink, complete);
+        
Assertions.assertNotNull(complete.getCascadesContext().getIvmRewriteResult().orElseThrow()
+                .getPlanSignature());
+    }
+
     @Test
     void testMowNormalizeRejectsRootWithoutSink() {
         JobContext jobContext = newJobContextForRoot(scan, true, 
Collections.emptySet(),
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/mtmv/ivm/IvmRewriteContextTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/mtmv/ivm/IvmRewriteContextTest.java
index 685d31b70a5..87533a96fec 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/mtmv/ivm/IvmRewriteContextTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/mtmv/ivm/IvmRewriteContextTest.java
@@ -37,7 +37,6 @@ class IvmRewriteContextTest {
     void testCreateModeAllowsNullMtmv() {
         IvmRewriteContext context = IvmRewriteContext.create("test_mtmv");
 
-        Assertions.assertEquals(IvmRewriteContext.Mode.CREATE, 
context.getMode());
         Assertions.assertTrue(context.isCreate());
         Assertions.assertNull(context.getMtmv());
         Assertions.assertEquals("test_mtmv", context.getMtmvName());
@@ -60,18 +59,19 @@ class IvmRewriteContextTest {
 
         IvmRewriteContext context = IvmRewriteContext.normalize(mtmv);
 
-        Assertions.assertEquals(IvmRewriteContext.Mode.NORMALIZE, 
context.getMode());
+        Assertions.assertTrue(context.isNormalize());
         Assertions.assertSame(mtmv, context.getMtmv());
         Assertions.assertFalse(context.isIncludeExhaustedStreams());
     }
 
     @Test
-    void testFullModeAlwaysDisablesIncludeUpToDateStreams() {
+    void testCompleteModeAlwaysDisablesIncludeUpToDateStreams() {
         MTMV mtmv = Mockito.mock(MTMV.class);
 
-        IvmRewriteContext context = IvmRewriteContext.full(mtmv);
+        IvmRewriteContext context = IvmRewriteContext.complete(mtmv);
 
-        Assertions.assertEquals(IvmRewriteContext.Mode.FULL, 
context.getMode());
+        Assertions.assertTrue(context.isCompleteRefresh());
+        Assertions.assertTrue(context.isPartitionBasedRefresh());
         Assertions.assertSame(mtmv, context.getMtmv());
         Assertions.assertFalse(context.isIncludeExhaustedStreams());
         Assertions.assertFalse(context.hasFullRefreshStreamScans());
@@ -86,10 +86,12 @@ class IvmRewriteContextTest {
         Map<BaseTableInfo, Set<Long>> resetScopes = new HashMap<>();
         resetScopes.put(resetTable, resetPartitionIds);
 
-        IvmRewriteContext context = IvmRewriteContext.full(mtmv,
+        IvmRewriteContext context = IvmRewriteContext.partitions(mtmv,
                 resetScopes, StreamReadMode.SNAPSHOT);
         resetPartitionIds.add(2L);
 
+        Assertions.assertTrue(context.isPartitionsRefresh());
+        Assertions.assertTrue(context.isPartitionBasedRefresh());
         Assertions.assertTrue(context.hasFullRefreshStreamScans());
         Set<Long> firstRead = 
context.getFullRefreshResetPartitionIds(resetTable).orElseThrow();
         Assertions.assertEquals(Collections.singleton(1L), firstRead);
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CollectRelationChangelogTtlTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CollectRelationChangelogTtlTest.java
index b9f93c3bf93..16c77e038d3 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CollectRelationChangelogTtlTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CollectRelationChangelogTtlTest.java
@@ -100,10 +100,10 @@ class CollectRelationChangelogTtlTest extends 
TestWithFeService {
     @Test
     void testFullIvmSnapshotRegistersButResetDoesNot() {
         MTMV mv = Mockito.mock(MTMV.class);
-        Assertions.assertTrue(collect("select * from changelog_base", 
Optional.of(IvmRewriteContext.full(
+        Assertions.assertTrue(collect("select * from changelog_base", 
Optional.of(IvmRewriteContext.complete(
                 mv, Collections.emptyMap(), StreamReadMode.SNAPSHOT)))
                 .isChangelogReferenceTsoRequired());
-        Assertions.assertFalse(collect("select * from changelog_base", 
Optional.of(IvmRewriteContext.full(mv)))
+        Assertions.assertFalse(collect("select * from changelog_base", 
Optional.of(IvmRewriteContext.complete(mv)))
                 .isChangelogReferenceTsoRequired());
         Assertions.assertFalse(collect("select * from changelog_base", 
Optional.of(IvmRewriteContext.normalize(mv)))
                 .isChangelogReferenceTsoRequired());
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/IvmFullRefreshMTMVTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/IvmFullRefreshMTMVTest.java
index 8a52e4312dd..f1f0ade7f39 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/IvmFullRefreshMTMVTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/IvmFullRefreshMTMVTest.java
@@ -201,7 +201,7 @@ public class IvmFullRefreshMTMVTest extends 
TestWithFeService {
     public void testFullContextWithoutStreamScansDoesNotRewrite() throws 
Exception {
         OlapTable baseTable = baseTable();
         LogicalOlapScan scan = newOlapScan(baseTable, 
baseTable.getPartitionIds());
-        Plan result = rewrite(scan, IvmRewriteContext.full(mtmv()));
+        Plan result = rewrite(scan, IvmRewriteContext.complete(mtmv()));
 
         Assertions.assertSame(scan, result);
     }
@@ -211,7 +211,7 @@ public class IvmFullRefreshMTMVTest extends 
TestWithFeService {
         OlapTable baseTable = baseTable();
         LogicalOlapScan scan = newOlapScan(baseTable, 
baseTable.getPartitionIds());
 
-        Plan result = rewrite(scan, IvmRewriteContext.fullExplain(mtmv()));
+        Plan result = rewrite(scan, IvmRewriteContext.completeExplain(mtmv()));
 
         Assertions.assertTrue(result instanceof LogicalProject);
         Plan child = ((LogicalProject<?>) result).child();
@@ -234,7 +234,7 @@ public class IvmFullRefreshMTMVTest extends 
TestWithFeService {
         partitionInfo.setPctInfos(ImmutableList.of(new BaseColInfo("k1", new 
BaseTableInfo(baseTable))));
         Mockito.when(mtmv.getMvPartitionInfo()).thenReturn(partitionInfo);
 
-        Plan result = rewrite(scan, IvmRewriteContext.fullExplain(mtmv));
+        Plan result = rewrite(scan, IvmRewriteContext.completeExplain(mtmv));
 
         Assertions.assertTrue(result instanceof LogicalProject);
         Plan child = ((LogicalProject<?>) result).child();
@@ -253,7 +253,7 @@ public class IvmFullRefreshMTMVTest extends 
TestWithFeService {
         // No stream exists for this MV id: a full refresh reads through one, 
and EXPLAIN plans the
         // same read, so it fails the same way instead of falling back to an 
ordinary base scan.
         Assertions.assertThrows(IvmException.class,
-                () -> rewrite(scan, IvmRewriteContext.fullExplain(mtmv(MV_ID + 
1, "missing_mv"))));
+                () -> rewrite(scan, 
IvmRewriteContext.completeExplain(mtmv(MV_ID + 1, "missing_mv"))));
     }
 
     @Test
@@ -326,7 +326,7 @@ public class IvmFullRefreshMTMVTest extends 
TestWithFeService {
                 .orElseGet(ImmutableMap::of);
         StreamReadMode nonPctReadMode = resetPartitionIds.isPresent()
                 ? StreamReadMode.RESET : StreamReadMode.SNAPSHOT;
-        return IvmRewriteContext.full(mtmv, resetScopes, nonPctReadMode);
+        return IvmRewriteContext.complete(mtmv, resetScopes, nonPctReadMode);
     }
 
     private Plan normalizeStreamScan(Plan plan) throws Exception {
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 93e6d491b15..d24dee0dc19 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
@@ -33,7 +33,6 @@ import org.apache.doris.common.util.PropertyAnalyzer;
 import org.apache.doris.mtmv.MTMVAlterOpType;
 import org.apache.doris.mtmv.MTMVRefreshEnum.MTMVState;
 import org.apache.doris.mtmv.MTMVRefreshEnum.RefreshMethod;
-import org.apache.doris.mtmv.ivm.IvmRewriteContext;
 import org.apache.doris.mtmv.ivm.IvmUtil;
 import org.apache.doris.nereids.StatementContext;
 import org.apache.doris.nereids.exceptions.AnalysisException;
@@ -1766,8 +1765,7 @@ public class CreateMTMVCommandTest extends 
TestWithFeService {
                 + " AS SELECT k1, v1 FROM ivm_context_base;");
 
         Assertions.assertTrue(info.isEnableIvm());
-        Assertions.assertEquals(IvmRewriteContext.Mode.CREATE,
-                
connectContext.getStatementContext().getIvmRewriteContext().orElseThrow().getMode());
+        
Assertions.assertTrue(connectContext.getStatementContext().getIvmRewriteContext().orElseThrow().isCreate());
     }
 
     @Test
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/UpdateMvByPartitionCommandTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/UpdateMvByPartitionCommandTest.java
index 0de2d27fabb..b312f3fb84c 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/UpdateMvByPartitionCommandTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/UpdateMvByPartitionCommandTest.java
@@ -170,7 +170,7 @@ class UpdateMvByPartitionCommandTest extends 
TestWithFeService {
     @Test
     void testAnalyzeRefreshCommandBindsSinkAfterRowIdNormalization() throws 
Exception {
         MTMV mtmv = getMtmv("ivm_mv");
-        
connectContext.getStatementContext().setIvmRewriteContext(Optional.of(IvmRewriteContext.full(mtmv)));
+        
connectContext.getStatementContext().setIvmRewriteContext(Optional.of(IvmRewriteContext.complete(mtmv)));
         UpdateMvByPartitionCommand command = newRefreshCommand(mtmv);
         LogicalOlapTableSink<?> sink = (LogicalOlapTableSink<?>) 
PlanChecker.from(connectContext,
                 
command.getLogicalQuery()).analyze(command.getLogicalQuery()).getPlan();
@@ -186,7 +186,7 @@ class UpdateMvByPartitionCommandTest extends 
TestWithFeService {
     @Test
     void testAnalyzeRefreshCommandBindsDetailMvSinkWithoutRowId() throws 
Exception {
         MTMV mtmv = getMtmv("ivm_mv_detail");
-        
connectContext.getStatementContext().setIvmRewriteContext(Optional.of(IvmRewriteContext.full(mtmv)));
+        
connectContext.getStatementContext().setIvmRewriteContext(Optional.of(IvmRewriteContext.complete(mtmv)));
         UpdateMvByPartitionCommand command = newRefreshCommand(mtmv);
         LogicalOlapTableSink<?> sink = (LogicalOlapTableSink<?>) 
PlanChecker.from(connectContext,
                 
command.getLogicalQuery()).analyze(command.getLogicalQuery()).getPlan();
@@ -206,7 +206,7 @@ class UpdateMvByPartitionCommandTest extends 
TestWithFeService {
         MTMV mtmv = getMtmv("ivm_mv_uniq");
         UpdateMvByPartitionCommand command = newRefreshCommand(mtmv);
         StatementContext statementContext = createStatementCtx("refresh 
materialized view test.ivm_mv_uniq");
-        
statementContext.setIvmRewriteContext(Optional.of(IvmRewriteContext.full(mtmv)));
+        
statementContext.setIvmRewriteContext(Optional.of(IvmRewriteContext.complete(mtmv)));
         TestNereidsPlanner planner = new TestNereidsPlanner(statementContext);
         PhysicalPlan physicalPlan = 
planner.planWithLock(command.getLogicalQuery(), PhysicalProperties.ANY);
         PlanTranslatorContext translatorContext = new 
PlanTranslatorContext(planner.getCascadesContext());
@@ -238,7 +238,7 @@ class UpdateMvByPartitionCommandTest extends 
TestWithFeService {
         MTMV mtmv = getMtmv("ivm_mv");
         UpdateMvByPartitionCommand command = newRefreshCommand(mtmv);
         StatementContext statementContext = createStatementCtx("refresh 
materialized view test.ivm_mv");
-        
statementContext.setIvmRewriteContext(Optional.of(IvmRewriteContext.full(mtmv)));
+        
statementContext.setIvmRewriteContext(Optional.of(IvmRewriteContext.complete(mtmv)));
         TestNereidsPlanner planner = new TestNereidsPlanner(statementContext);
         PhysicalPlan physicalPlan = 
planner.planWithLock(command.getLogicalQuery(), PhysicalProperties.ANY);
         PlanTranslatorContext translatorContext = new 
PlanTranslatorContext(planner.getCascadesContext());
@@ -268,7 +268,7 @@ class UpdateMvByPartitionCommandTest extends 
TestWithFeService {
         MTMV mtmv = getMtmv("ivm_mv");
         StatementContext statementContext = createStatementCtx("refresh 
materialized view test.ivm_mv");
         OriginStatement originStatement = 
statementContext.getOriginStatement();
-        
statementContext.setIvmRewriteContext(Optional.of(IvmRewriteContext.full(mtmv)));
+        
statementContext.setIvmRewriteContext(Optional.of(IvmRewriteContext.complete(mtmv)));
         UpdateMvByPartitionCommand command = newRefreshCommand(mtmv);
         AtomicReference<StmtExecutor> executorRef = new AtomicReference<>();
         MTMVPlanUtil.executeCommand(
@@ -283,8 +283,8 @@ class UpdateMvByPartitionCommandTest extends 
TestWithFeService {
         Assertions.assertNotNull(executor);
         
Assertions.assertFalse(executor.getContext().getSessionVariable().isEnableMaterializedViewRewrite());
         
Assertions.assertFalse(executor.getContext().getSessionVariable().isEnableDmlMaterializedViewRewrite());
-        Assertions.assertEquals(IvmRewriteContext.Mode.FULL,
-                
executor.getContext().getStatementContext().getIvmRewriteContext().orElseThrow().getMode());
+        
Assertions.assertTrue(executor.getContext().getStatementContext().getIvmRewriteContext().orElseThrow()
+                .isCompleteRefresh());
         Assertions.assertSame(executor.getContext(), 
statementContext.getConnectContext());
         Assertions.assertSame(statementContext, 
executor.getContext().getStatementContext());
         Assertions.assertSame(originStatement, 
statementContext.getOriginStatement());
@@ -296,7 +296,7 @@ class UpdateMvByPartitionCommandTest extends 
TestWithFeService {
         MTMV mtmv = getMtmv("ivm_mv");
         StatementContext statementContext = createStatementCtx("refresh 
materialized view test.ivm_mv");
         OriginStatement originStatement = 
statementContext.getOriginStatement();
-        
statementContext.setIvmRewriteContext(Optional.of(IvmRewriteContext.full(mtmv)));
+        
statementContext.setIvmRewriteContext(Optional.of(IvmRewriteContext.complete(mtmv)));
         UpdateMvByPartitionCommand command = UpdateMvByPartitionCommand.from(
                 mtmv, Sets.newHashSet(), ImmutableMap.of(), statementContext);
         AtomicReference<StmtExecutor> executorRef = new AtomicReference<>();
@@ -362,7 +362,7 @@ class UpdateMvByPartitionCommandTest extends 
TestWithFeService {
 
     private UpdateMvByPartitionCommand newRefreshCommand(MTMV mtmv) throws 
Exception {
         StatementContext statementContext = createStatementCtx("refresh 
materialized view test.ivm_mv");
-        
statementContext.setIvmRewriteContext(Optional.of(IvmRewriteContext.full(mtmv)));
+        
statementContext.setIvmRewriteContext(Optional.of(IvmRewriteContext.complete(mtmv)));
         return UpdateMvByPartitionCommand.from(mtmv, Sets.newHashSet(), 
ImmutableMap.of(), statementContext);
     }
 
diff --git 
a/regression-test/data/mtmv_p0/ivm/test_ivm_partition_signature_fallback.out 
b/regression-test/data/mtmv_p0/ivm/test_ivm_partition_signature_fallback.out
new file mode 100644
index 00000000000..d33a943be0a
--- /dev/null
+++ b/regression-test/data/mtmv_p0/ivm/test_ivm_partition_signature_fallback.out
@@ -0,0 +1,28 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !strict_partitions --
+FAILED NONE
+
+-- !strict_incremental --
+FAILED NONE
+
+-- !rows_after_rejected_refreshes --
+2026-01-10     1       10
+2026-02-10     2       20
+
+-- !complete_fallback --
+SUCCESS        COMPLETE
+
+-- !rows_after_complete --
+2026-01-10     1       10
+2026-01-11     3       30
+2026-02-10     2       20
+
+-- !matching_partitions --
+SUCCESS        PARTITION_REBUILD
+
+-- !rows_after_matching_refresh --
+2026-01-10     1       10
+2026-01-11     3       30
+2026-02-10     2       20
+2026-02-11     4       40
+
diff --git 
a/regression-test/suites/mtmv_p0/ivm/test_ivm_partition_signature_fallback.groovy
 
b/regression-test/suites/mtmv_p0/ivm/test_ivm_partition_signature_fallback.groovy
new file mode 100644
index 00000000000..ffc05a22be2
--- /dev/null
+++ 
b/regression-test/suites/mtmv_p0/ivm/test_ivm_partition_signature_fallback.groovy
@@ -0,0 +1,93 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_ivm_partition_signature_fallback", "nonConcurrent") {
+    sql "SET enable_materialized_view_rewrite=false"
+    sql "SET enable_dml_materialized_view_rewrite=false"
+
+    def mvName = "ivm_part_sig_mv"
+    def signatureSaltDebugPoint = 
"IvmPlanSignatureGenerator.generate.signature_salt"
+
+    sql "DROP MATERIALIZED VIEW IF EXISTS ivm_part_sig_mv"
+    sql "DROP TABLE IF EXISTS ivm_part_sig_t"
+    sql """
+        CREATE TABLE ivm_part_sig_t (
+            dt DATE NOT NULL,
+            id INT NOT NULL,
+            v INT
+        )
+        UNIQUE KEY(dt, id)
+        PARTITION BY RANGE(dt) (
+            PARTITION p1 VALUES [('2026-01-01'), ('2026-02-01')),
+            PARTITION p2 VALUES [('2026-02-01'), ('2026-03-01'))
+        )
+        DISTRIBUTED BY HASH(id) BUCKETS 1
+        PROPERTIES (
+            'replication_num' = '1',
+            'enable_unique_key_merge_on_write' = 'true',
+            'changelog.enable' = 'true',
+            'changelog.need_historical_value' = 'true'
+        )
+    """
+    sql "INSERT INTO ivm_part_sig_t VALUES ('2026-01-10', 1, 10), 
('2026-02-10', 2, 20)"
+    sql """
+        CREATE MATERIALIZED VIEW ivm_part_sig_mv
+        BUILD DEFERRED REFRESH INCREMENTAL ON MANUAL
+        PARTITION BY(dt)
+        DISTRIBUTED BY HASH(id) BUCKETS 1
+        PROPERTIES ('replication_num' = '1', 'refresh_partition_num' = '1')
+        AS SELECT dt, id, v FROM ivm_part_sig_t
+    """
+    refreshIvm(mvName, "REFRESH MATERIALIZED VIEW ivm_part_sig_mv COMPLETE")
+    assertEquals("SUCCESS", latestIvmTask(mvName).Status.toString())
+    sql "INSERT INTO ivm_part_sig_t VALUES ('2026-01-11', 3, 30)"
+
+    def taskMethodQuery = { task ->
+        """SELECT Status, IvmRefreshMethod FROM tasks('type' = 'mv')
+           WHERE MvDatabaseName = '${context.dbName}' AND MvName = '${mvName}'
+             AND TaskId = '${task.TaskId}'
+           ORDER BY TaskId"""
+    }
+    try {
+        GetDebugPoint().enableDebugPointForAllFEs(signatureSaltDebugPoint, 
[value: "partition_layout_changed"])
+        refreshIvm(mvName, "REFRESH MATERIALIZED VIEW ivm_part_sig_mv 
PARTITIONS")
+        def strictPartitions = latestIvmTask(mvName)
+        assertTrue(strictPartitions.ErrorMsg.toString().contains("IVM layout 
signature mismatch"))
+        qt_strict_partitions taskMethodQuery(strictPartitions)
+
+        // The failed partition refresh left a rebuild requirement, so this 
reaches the incremental rebuild path.
+        refreshIvm(mvName, "REFRESH MATERIALIZED VIEW ivm_part_sig_mv 
INCREMENTAL")
+        def strictIncremental = latestIvmTask(mvName)
+        assertTrue(strictIncremental.ErrorMsg.toString().contains("IVM layout 
signature mismatch"))
+        qt_strict_incremental taskMethodQuery(strictIncremental)
+        order_qt_rows_after_rejected_refreshes "SELECT dt, id, v FROM 
ivm_part_sig_mv"
+
+        refreshIvm(mvName, "REFRESH MATERIALIZED VIEW ivm_part_sig_mv 
PARTITIONS FALLBACK")
+        def fallback = latestIvmTask(mvName)
+        assertEquals("PLAN_SIGNATURE_MISMATCH", 
fallback.IvmFallbackReason.toString())
+        qt_complete_fallback taskMethodQuery(fallback)
+        order_qt_rows_after_complete "SELECT dt, id, v FROM ivm_part_sig_mv"
+
+        // The COMPLETE published the new signature, so a later strict 
partition refresh can use it.
+        sql "INSERT INTO ivm_part_sig_t VALUES ('2026-02-11', 4, 40)"
+        refreshIvm(mvName, "REFRESH MATERIALIZED VIEW ivm_part_sig_mv 
PARTITIONS")
+        qt_matching_partitions taskMethodQuery(latestIvmTask(mvName))
+        order_qt_rows_after_matching_refresh "SELECT dt, id, v FROM 
ivm_part_sig_mv"
+    } finally {
+        GetDebugPoint().disableDebugPointForAllFEs(signatureSaltDebugPoint)
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to