Skip to content

[fix](ivm) Refresh the surviving partitions after an IVM baseline rebuild - #67802

Merged
yujun777 merged 2 commits into
apache:masterfrom
yujun777:fix-ivm-baseline-rebuild
Sep 11, 2026
Merged

[fix](ivm) Refresh the surviving partitions after an IVM baseline rebuild#67802
yujun777 merged 2 commits into
apache:masterfrom
yujun777:fix-ivm-baseline-rebuild

Conversation

@yujun777

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Dropping a base-table partition marks the IVM baseline as broken, because those rows disappear through metadata rather than through row binlog entries. Partition sync then removes the very MV partitions that barrier named, so handlePendingIvmBaselineRebuild intersected the barrier with the current MV partitions and always got an empty set. The refresh reported SUCCESS with refresh mode NOT_REFRESH and cleared the barrier without refreshing anything, leaving the delta that had accumulated on the surviving partitions unapplied: the task claimed the MV was up to date while the MV was missing rows.

Reproduction: drop a base partition, insert a row into a surviving partition, then run REFRESH MATERIALIZED VIEW ... INCREMENTAL FALLBACK. The task succeeds, the expired MV partition is dropped, and the new row never reaches the MV.

What changed

  • MTMVTask.handlePendingIvmBaselineRebuild is a pre-step now instead of a terminal branch. It rebuilds only the barrier partitions that still exist, releases the barrier, and then lets the normal attempt list run, so the surviving partitions catch up in the same task. Partitions the barrier named that partition sync already dropped need no rebuild: the partition and its IVM offsets are both gone, which is what satisfies those entries.
  • The attempt list is rewritten in place. A lone COMPLETE attempt rebuilds everything anyway and needs no pre-rebuild; a complete baseline rebuild rewrites the list to COMPLETE instead of executing it inline.
  • MTMV.releaseIvmBaselineRebuild releases the barrier under a schemaChangeVersion compare-and-clear and journals the new state immediately, like the other ivmInfo mutations. Without the release the IVM attempt that follows would be rejected by validateIvmRefreshStart; without the compare-and-clear a concurrent base-table change would lose the barrier entry it had just recorded.
  • MTMVRelationManager.markIvmBaselineRebuild takes an explicit all-partitions-changed flag instead of inferring it from an empty partition map.

The COMPLETE paths are unchanged. They end the task, so the existing addTaskResult cleanup releases the barrier once the refresh succeeds.

A strict REFRESH ... INCREMENTAL, and a scheduled refresh of an MV declared without FALLBACK, still fail while the barrier is pending, because that check runs before partition sync. Relaxing it is left to a follow-up PR.

Test

  • regression-test/suites/mtmv_p0/ivm/test_ivm_partition_drop_live_delta.groovy (new): partitions added and dropped by hand with literal dates and no dynamic-partition scheduler, so the case is deterministic. Asserts the MV matches the base table right after INCREMENTAL FALLBACK. The scenario was reproduced on the pre-fix build, where the fallback task reported SUCCESS while the MV was missing the row written to the surviving partition.
  • regression-test/suites/mtmv_p0/ivm/test_ivm_partition_baseline_rebuild_dup_keys.groovy (new): covers the TRUNCATE path, where the affected MV partition survives and the pre-step really has something to rebuild. Runs on a duplicate-key MV with repeated identical rows, so a delta applied twice would show up as extra rows instead of hiding behind a unique key.
  • test_ivm_partition_baseline_rebuild, test_ivm_partition_sync_retry, test_ivm_partition_unique_key, test_ivm_partition_window_limit, test_ivm_partition_window_remove, test_ivm_one_row_relation_partitioned, test_ivm_strict_failure_partition_atomicity

Trace issue: #65418

…uild

Dropping a base-table partition marks the IVM baseline as broken, and partition sync then
removes the very MV partitions that barrier named. handlePendingIvmBaselineRebuild derived
its rebuild set from the intersection of the barrier with the current MV partitions, so that
set was always empty: the task reported SUCCESS with refresh mode NOT_REFRESH and cleared the
barrier without refreshing anything, leaving the delta accumulated on the surviving partitions
unapplied while the MV claimed to be up to date.

Treat the pending baseline rebuild as a pre-step instead of a terminal branch, so the attempt
list still runs and the surviving partitions catch up in the same task.

Key changes:
- MTMVTask.handlePendingIvmBaselineRebuild rebuilds only the barrier partitions that still exist, releases the barrier and then lets the normal attempts run instead of returning early
- the attempt list is rewritten in place: a lone COMPLETE attempt needs no pre-rebuild, and a complete baseline rebuild rewrites the list to COMPLETE rather than executing it inline
- add MTMV.releaseIvmBaselineRebuild, which compare-and-clears on schemaChangeVersion and journals the new state immediately like the other ivmInfo mutations, so the IVM attempt that follows is not rejected by validateIvmRefreshStart
- MTMVRelationManager.markIvmBaselineRebuild takes an explicit all-partitions-changed flag instead of inferring it from an empty partition map

Unit Test:
- test_ivm_partition_drop_live_delta: new, partitions added and dropped by hand with literal dates, asserts the MV matches the base table right after INCREMENTAL FALLBACK
- test_ivm_partition_baseline_rebuild_dup_keys: new, covers the TRUNCATE path where the affected MV partition survives, on a duplicate-key MV so a double-applied delta would show up as extra rows
- test_ivm_partition_baseline_rebuild, test_ivm_partition_sync_retry, test_ivm_partition_unique_key, test_ivm_partition_window_limit, test_ivm_partition_window_remove, test_ivm_one_row_relation_partitioned, test_ivm_strict_failure_partition_atomicity
@yujun777
yujun777 requested a review from morrySnow as a code owner September 10, 2026 10:24
@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?

@yujun777

Copy link
Copy Markdown
Contributor Author

run buildall

@yujun777

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 17000 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 6ea4990f69b2a4ac98a5e839adc5e58694b56846, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17560	3052	3064	3052
q2	2116	269	227	227
q3	10195	902	514	514
q4	4674	254	207	207
q5	7660	565	391	391
q6	136	116	96	96
q7	525	501	392	392
q8	9232	885	967	885
q9	3439	2435	2418	2418
q10	6543	885	726	726
q11	404	201	180	180
q12	611	261	197	197
q13	18142	1541	1185	1185
q14	163	149	145	145
q15	q16	446	401	367	367
q17	1374	908	847	847
q18	3160	2245	2260	2245
q19	1272	839	820	820
q20	369	285	201	201
q21	5601	1674	1872	1674
q22	340	274	231	231
Total cold run time: 93962 ms
Total hot run time: 17000 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3438	3360	3341	3341
q2	498	404	378	378
q3	2233	2397	2201	2201
q4	1216	1182	909	909
q5	2220	2129	2138	2129
q6	171	123	89	89
q7	1028	931	890	890
q8	1599	1405	1414	1405
q9	3218	3153	3160	3153
q10	1909	1844	1678	1678
q11	359	274	253	253
q12	461	443	346	346
q13	1510	1539	1177	1177
q14	173	166	170	166
q15	q16	394	401	367	367
q17	3675	3434	3311	3311
q18	4881	4510	4915	4510
q19	955	853	864	853
q20	1014	993	837	837
q21	3909	3194	3267	3194
q22	390	338	326	326
Total cold run time: 35251 ms
Total hot run time: 31513 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 82896 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 6ea4990f69b2a4ac98a5e839adc5e58694b56846, data reload: false

query5	4250	416	337	337
query6	400	141	133	133
query7	4916	398	241	241
query8	293	132	119	119
query9	8693	2927	2912	2912
query10	415	236	195	195
query11	5407	1081	957	957
query12	129	73	72	72
query13	1193	469	330	330
query14	6182	2223	2116	2116
query14_1	2018	1977	2010	1977
query15	186	122	112	112
query16	923	396	363	363
query17	807	469	357	357
query18	2334	326	245	245
query19	161	145	111	111
query20	93	75	75	75
query21	202	102	89	89
query22	5492	5395	5395	5395
query23	6884	6294	6189	6189
query23_1	6361	6404	6075	6075
query24	7272	1077	761	761
query24_1	798	769	766	766
query25	435	306	254	254
query26	1231	243	128	128
query27	2776	412	271	271
query28	4675	1497	1512	1497
query29	934	436	365	365
query30	269	151	135	135
query31	818	411	345	345
query32	133	76	79	76
query33	458	231	187	187
query34	995	833	489	489
query35	415	413	354	354
query36	559	584	525	525
query37	121	93	74	74
query38	1034	874	834	834
query39	493	496	488	488
query39_1	489	476	468	468
query40	199	91	80	80
query41	95	52	55	52
query42	79	71	71	71
query43	243	244	209	209
query44	977	543	562	543
query45	108	108	98	98
query46	746	835	533	533
query47	776	752	714	714
query48	320	294	225	225
query49	539	251	197	197
query50	737	261	193	193
query51	8235	8316	8235	8235
query52	73	74	66	66
query53	183	195	147	147
query54	224	154	147	147
query55	68	61	53	53
query56	193	162	156	156
query57	724	677	645	645
query58	196	165	171	165
query59	1242	1268	1102	1102
query60	231	183	168	168
query61	120	107	114	107
query62	376	210	178	178
query63	176	138	145	138
query64	2716	669	575	575
query65	1652	1653	1634	1634
query66	1785	260	201	201
query67	10034	9923	9884	9884
query68	3030	1234	695	695
query69	349	221	193	193
query70	655	631	621	621
query71	246	178	170	170
query72	2284	1707	1488	1488
query73	661	574	354	354
query74	2017	1231	1158	1158
query75	1200	1116	984	984
query76	2397	710	508	508
query77	249	258	207	207
query78	4087	3739	3188	3188
query79	2568	881	600	600
query80	1594	324	282	282
query81	516	153	132	132
query82	610	132	96	96
query83	281	214	188	188
query84	296	115	88	88
query85	816	339	284	284
query86	463	183	171	171
query87	1022	996	905	905
query88	2871	2083	2122	2083
query89	290	200	177	177
query90	1994	137	132	132
query91	127	116	98	98
query92	93	62	67	62
query93	1832	1075	713	713
query94	627	212	239	212
query95	525	277	230	230
query96	755	564	261	261
query97	1136	1050	996	996
query98	175	141	140	140
query99	417	345	313	313
Total cold run time: 179902 ms
Total hot run time: 82896 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 14.89 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 6ea4990f69b2a4ac98a5e839adc5e58694b56846, data reload: false

query1	0.01	0.00	0.01
query2	0.08	0.04	0.04
query3	0.24	0.10	0.11
query4	1.60	0.10	0.10
query5	0.17	0.15	0.16
query6	1.26	0.68	0.71
query7	0.04	0.01	0.00
query8	0.04	0.04	0.03
query9	0.27	0.22	0.22
query10	0.35	0.34	0.34
query11	0.16	0.12	0.12
query12	0.14	0.12	0.12
query13	0.31	0.32	0.31
query14	0.45	0.46	0.45
query15	0.36	0.36	0.35
query16	0.25	0.23	0.23
query17	0.70	0.68	0.70
query18	0.17	0.18	0.15
query19	1.23	1.22	1.20
query20	0.02	0.01	0.01
query21	15.42	0.16	0.12
query22	5.07	0.05	0.05
query23	16.17	0.25	0.11
query24	2.97	0.31	0.25
query25	0.10	0.04	0.03
query26	0.80	0.16	0.13
query27	0.04	0.03	0.04
query28	3.61	0.53	0.28
query29	12.50	3.20	2.56
query30	0.25	0.13	0.12
query31	2.76	0.37	0.18
query32	3.50	0.31	0.23
query33	1.38	1.54	1.47
query34	15.37	2.23	1.79
query35	1.79	1.76	1.75
query36	0.45	0.29	0.28
query37	0.06	0.04	0.03
query38	0.05	0.03	0.02
query39	0.03	0.03	0.02
query40	0.12	0.08	0.08
query41	0.08	0.03	0.03
query42	0.03	0.03	0.02
query43	0.04	0.03	0.03
Total cold run time: 90.44 s
Total hot run time: 14.89 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 41.18% (14/34) 🎉
Increment coverage report
Complete coverage report

@yujun777
yujun777 merged commit f8ed33f into apache:master Sep 11, 2026
33 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants