hello-stephen commented on code in PR #71190:
URL: https://github.com/apache/doris/pull/71190#discussion_r4750262008


##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPlanUtil.java:
##########
@@ -156,6 +164,144 @@ public static ConnectContext createMTMVContext(MTMV mtmv, 
List<RuleType> disable
         return ctx;
     }
 
+    /**
+     * Create an internal MTMV context for refresh execution, dry run, or 
EXPLAIN REFRESH.
+     * Explicit REFRESH SET_VAR hints are applied on top of MTMV defaults so 
they take
+     * precedence over both MTMV defaults and MV query SQL SET_VAR hints. 
Materialized view
+     * rewrite remains forcibly disabled to prevent self-rewrite during 
refresh and keep
+     * REFRESH, DRY RUN, and EXPLAIN REFRESH behavior consistent.
+     */
+    public static ConnectContext createMTMVRefreshContext(MTMV mtmv, 
List<RuleType> disableRules,
+            @Nullable Map<String, String> refreshSessionVariables) {
+        ConnectContext previousContext = ConnectContext.get();
+        ConnectContext ctx = createMTMVContext(mtmv, disableRules);
+        try {
+            applyRefreshSessionVariables(ctx, null, refreshSessionVariables);

Review Comment:
   [P1] Keep incremental refresh semantics consistent with its baseline
   
   This also applies result-changing overrides to incremental contexts. 
Consider an IVM MV defined as `SELECT /*+ SET_VAR(time_zone='+00:00') */ id 
FROM t WHERE FROM_UNIXTIME(ts,'%H')='00'`, with a changelog-enabled UNIQUE/MOW 
base. Build its baseline from `(id=1, ts=0)`, update that row to `ts=3600`, 
then run `REFRESH /*+ SET_VAR(time_zone='+02:00') */ MATERIALIZED VIEW mv 
INCREMENTAL`. The MV's UTC hint is now skipped, and 
`IvmLinearDeltaHandler.rewriteFilter` produces this reduced delta shape:
   
   ```text
   Project(id, row_id, dml_factor, sequence)
     Filter(FROM_UNIXTIME(ts,'%H') = '00')  [timezone +02]
       Stream(t: UPDATE_BEFORE ts=0, UPDATE_AFTER ts=3600)
   ```
   
   Both events fail the filter (hours `02` and `03`), so no retraction removes 
the stored `id=1`. The refresh succeeds and advances offsets, leaving a row 
that a fresh query excludes under either timezone. 
`IvmPlanSignatureGenerator.visitLogicalFilter` omits predicates, and timezone 
is absent from the layout signature, so the existing signature check does not 
prevent this. Please reject semantic overrides inconsistent with the maintained 
baseline or require a complete rebuild, and cover this UPDATE/DELETE case.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to