Skip to content

[fix](mtmv) Refresh MTMV after excluded trigger tables change#64041

Open
seawinde wants to merge 1 commit into
apache:masterfrom
seawinde:fix-exclude-trigger-table-full-refresh
Open

[fix](mtmv) Refresh MTMV after excluded trigger tables change#64041
seawinde wants to merge 1 commit into
apache:masterfrom
seawinde:fix-exclude-trigger-table-full-refresh

Conversation

@seawinde
Copy link
Copy Markdown
Member

@seawinde seawinde commented Jun 3, 2026

What problem does this PR solve?

Issue Number: N/A

Related PR: N/A

Problem Summary:
Changing the effective excluded_trigger_tables set changes which base tables participate in MTMV freshness decisions. Reusing the old refreshSnapshot can make a later AUTO refresh skip work under the new exclude rules, leaving MV data based on the old snapshot.

Root cause: In MTMVTask.calculateNeedRefreshPartitions(), AUTO refresh calls MTMVPartitionUtil.isMTMVSync() before verifying whether the refresh baseline is still complete. After ALTER MATERIALIZED VIEW ... SET ("excluded_trigger_tables"=...), the new exclude rules can skip changed base tables and incorrectly mark the MV as fresh.

File Change Description
MTMV.java Detect effective excluded_trigger_tables set changes, bump schemaChangeVersion, and clear refreshSnapshot without setting MTMVStatus.state to SCHEMA_CHANGE.
MTMVTask.java Treat incomplete refresh snapshots as requiring a complete AUTO refresh before calling isMTMVSync(). Manual specified-partition refresh keeps existing behavior.
MTMVTest.java Cover qualified-name changes, same-set order changes, reduced/cleared excluded table sets, and unrelated property changes.
MTMVTaskTest.java Cover incomplete-baseline AUTO refresh and manual specified-partition behavior.
test_excluded_trigger_table_mtmv.groovy Align the case comments with the expected refresh behavior.

Design rationale:
This uses the existing refreshSnapshot completeness as the invalid-baseline signal instead of adding a new persisted flag. That keeps the change scoped to the ALTER property path and AUTO refresh decision path. Query rewrite behavior is unchanged.

graph TD
    A[ALTER excluded_trigger_tables] --> B[Compare effective table-name set]
    B -->|changed| C[Clear refreshSnapshot]
    C --> D[Next AUTO refresh]
    D --> E{refreshSnapshot complete?}
    E -->|No| F[Refresh all MV partitions]
    E -->|Yes| G[Run isMTMVSync with current exclude rules]
Loading

Release note

Changing excluded_trigger_tables on an MTMV now invalidates the refresh baseline so the next AUTO refresh rebuilds it with a complete refresh.

Check List (For Author)

  • Test
    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason

./run-fe-ut.sh --run org.apache.doris.mtmv.MTMVTest,org.apache.doris.mtmv.MTMVTaskTest

Regression test was not run locally because no FE/BE cluster is available to generate the updated .out file.

  • Behavior changed:

    • No.
    • Yes. ALTER MATERIALIZED VIEW ... SET ("excluded_trigger_tables"=...) now invalidates the refresh baseline when the effective excluded table set changes. The next AUTO refresh performs a complete refresh if the baseline is incomplete.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

### What problem does this PR solve?

Issue Number: N/A

Related PR: N/A

Problem Summary: Changing the effective excluded_trigger_tables set changes which base tables participate in MTMV freshness decisions. Reusing the old refreshSnapshot can make a later AUTO refresh skip work under the new exclude rules, leaving MV data based on the old snapshot.

Root cause: In MTMVTask.calculateNeedRefreshPartitions(), AUTO refresh calls MTMVPartitionUtil.isMTMVSync() before verifying whether the refresh baseline is still complete. After ALTER excluded_trigger_tables, the new exclude rules can skip changed base tables and incorrectly mark the MV as fresh.

This change resets the refresh snapshot and bumps the MTMV schema change version when the effective excluded_trigger_tables set changes, without setting MTMVStatus.state to SCHEMA_CHANGE. AUTO refresh now treats an incomplete refresh snapshot as requiring a complete refresh, while manual specified-partition refresh keeps the existing behavior.

### Release note

Changing excluded_trigger_tables on an MTMV now invalidates the refresh baseline so the next AUTO refresh rebuilds it with a complete refresh.

### Check List (For Author)

- Test: Unit Test
    - ./run-fe-ut.sh --run org.apache.doris.mtmv.MTMVTest,org.apache.doris.mtmv.MTMVTaskTest
    - Regression test not run because no local FE/BE cluster is available to generate the updated .out file.
- Behavior changed: Yes. ALTER excluded_trigger_tables now invalidates the refresh baseline, and AUTO refresh performs a complete refresh when the baseline is incomplete.
- Does this need documentation: No
@hello-stephen
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@morrySnow
Copy link
Copy Markdown
Contributor

/review

@morrySnow
Copy link
Copy Markdown
Contributor

run buildall

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Jun 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

PR approved by anyone and no changes requested.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed for the actual GitHub PR diff. I did not find a concrete blocking issue.

Critical checkpoint conclusions:

  • Goal/test coverage: the change addresses AUTO refresh correctness after excluded_trigger_tables changes by invalidating the refresh baseline and forcing a full refresh when the snapshot baseline is incomplete. Unit and regression coverage were added for the changed scenarios.
  • Scope/focus: the actual PR is small and focused on MTMV excluded trigger table refresh behavior.
  • Concurrency/locking: MTMV property and snapshot mutations are performed under the MV write lock; the added read path uses the existing MV read-lock pattern.
  • Lifecycle/persistence: ALTER_PROPERTY replay recomputes the same property-change transition, and the mutated MTMV fields are persisted through the table image/state. No master/follower mismatch was identified.
  • Configuration/incompatibility: no new config item or incompatible storage/protocol change was introduced.
  • Parallel paths/special checks: manual refresh behavior remains prioritized before the incomplete-baseline AUTO check; COMPLETE refresh behavior remains unchanged.
  • Test results: I did not run tests in this review runner; I reviewed the added unit/regression coverage for determinism and relevance.
  • Observability/performance: no new observability requirement or material performance issue was identified.
  • Transaction/data correctness: the baseline invalidation prevents stale AUTO refresh decisions after excluded trigger rules change.

User focus: no additional user-provided review focus was supplied.

@hello-stephen
Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 95.65% (22/23) 🎉
Increment coverage report
Complete coverage report

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 29234 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 5ee376e769960e709685994dfdabaaa7cff4b66d, data reload: false

------ Round 1 ----------------------------------
orders	Doris	NULL	NULL	0	0	0	NULL	0	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	17613	4066	4010	4010
q2	q3	10782	1371	811	811
q4	4689	478	342	342
q5	7570	889	610	610
q6	188	182	145	145
q7	776	832	642	642
q8	9354	1505	1492	1492
q9	5754	4532	4536	4532
q10	6734	1815	1532	1532
q11	436	282	254	254
q12	639	424	302	302
q13	18118	3394	2794	2794
q14	260	259	243	243
q15	q16	823	779	715	715
q17	964	1005	927	927
q18	7110	5795	5543	5543
q19	1334	1405	1069	1069
q20	528	407	262	262
q21	6200	2817	2697	2697
q22	457	389	312	312
Total cold run time: 100329 ms
Total hot run time: 29234 ms

----- Round 2, with runtime_filter_mode=off -----
orders	Doris	NULL	NULL	150000000	42	6422171781	NULL	22778155	NULL	NULL	2023-12-26 18:27:23	2023-12-26 18:42:55	NULL	utf-8	NULL	NULL	
============================================
q1	5159	4597	4810	4597
q2	q3	4888	5356	4715	4715
q4	2118	2184	1419	1419
q5	4820	4943	4647	4647
q6	234	177	140	140
q7	1865	1854	1560	1560
q8	2465	2179	2143	2143
q9	7922	7693	7362	7362
q10	4737	4662	4215	4215
q11	538	392	380	380
q12	735	729	525	525
q13	3080	3362	2817	2817
q14	268	278	249	249
q15	q16	675	690	626	626
q17	1310	1285	1286	1285
q18	7267	6914	6891	6891
q19	1154	1074	1125	1074
q20	2228	2223	1959	1959
q21	5310	4603	4536	4536
q22	512	464	420	420
Total cold run time: 57285 ms
Total hot run time: 51560 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 169870 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 5ee376e769960e709685994dfdabaaa7cff4b66d, data reload: false

query5	4336	616	481	481
query6	468	206	193	193
query7	4941	518	305	305
query8	380	219	232	219
query9	8745	4056	4069	4056
query10	450	324	259	259
query11	5920	2339	2181	2181
query12	156	106	104	104
query13	1275	589	417	417
query14	6458	5455	5083	5083
query14_1	4468	4405	4418	4405
query15	213	228	174	174
query16	985	408	431	408
query17	1045	710	597	597
query18	2419	472	347	347
query19	200	178	139	139
query20	116	108	108	108
query21	218	135	120	120
query22	13722	13508	13451	13451
query23	17235	16485	16231	16231
query23_1	16312	16247	16328	16247
query24	7495	1751	1306	1306
query24_1	1294	1339	1305	1305
query25	551	443	387	387
query26	1352	312	161	161
query27	2649	574	327	327
query28	4406	2023	2016	2016
query29	1080	611	489	489
query30	317	237	204	204
query31	1121	1084	968	968
query32	104	60	59	59
query33	523	310	261	261
query34	1190	1131	655	655
query35	764	788	697	697
query36	1406	1392	1244	1244
query37	155	116	96	96
query38	3208	3147	3067	3067
query39	955	922	892	892
query39_1	877	884	886	884
query40	225	129	108	108
query41	72	68	72	68
query42	98	99	100	99
query43	336	324	290	290
query44	
query45	198	189	188	188
query46	1071	1159	771	771
query47	2328	2354	2273	2273
query48	412	436	302	302
query49	642	489	369	369
query50	977	365	254	254
query51	4333	4395	4247	4247
query52	92	95	81	81
query53	252	287	195	195
query54	290	238	234	234
query55	83	82	73	73
query56	280	262	233	233
query57	1460	1419	1339	1339
query58	259	229	223	223
query59	1598	1693	1451	1451
query60	303	267	267	267
query61	195	188	190	188
query62	707	669	597	597
query63	242	187	191	187
query64	2649	875	701	701
query65	
query66	1799	481	347	347
query67	29762	29911	29525	29525
query68	
query69	421	302	271	271
query70	983	924	939	924
query71	285	220	206	206
query72	3009	2667	2377	2377
query73	854	735	436	436
query74	5157	4953	4799	4799
query75	2653	2579	2255	2255
query76	2353	1141	752	752
query77	347	379	280	280
query78	12508	12429	11902	11902
query79	1395	1067	785	785
query80	592	468	390	390
query81	461	282	242	242
query82	555	157	131	131
query83	400	282	260	260
query84	279	142	112	112
query85	878	543	439	439
query86	374	293	290	290
query87	3369	3369	3182	3182
query88	3662	2769	2741	2741
query89	432	381	331	331
query90	1974	179	182	179
query91	181	175	145	145
query92	68	67	58	58
query93	1504	1434	956	956
query94	554	365	321	321
query95	685	374	434	374
query96	1060	790	326	326
query97	2706	2679	2579	2579
query98	222	207	206	206
query99	1136	1178	1054	1054
Total cold run time: 251567 ms
Total hot run time: 169870 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. dev/4.1.x reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants