Skip to content

[fix](be) Materialize const columns before block merge#65770

Open
Gabriel39 wants to merge 1 commit into
apache:masterfrom
Gabriel39:agent/fix-iceberg-row-lineage-const-merge
Open

[fix](be) Materialize const columns before block merge#65770
Gabriel39 wants to merge 1 commit into
apache:masterfrom
Gabriel39:agent/fix-iceberg-row-lineage-const-merge

Conversation

@Gabriel39

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: None

Related PR: None

Related Jira: DORIS-27180

Problem Summary:

ScopedMutableBlock can retain a ColumnConst destination, while block merge materializes the incoming column before appending it. Appending that full column to the const destination fails with an internal error.

This change materializes a const destination once before appending, keeping the destination and source representations compatible for both regular and ignore-overflow merges.

Release note

Fix block merge failures when scanner padding produces constant nullable columns.

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
  • Behavior changed:

    • No.
    • Yes.
  • 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: None

Problem Summary:

MutableBlock can retain ColumnConst destinations while merge materializes incoming columns. Appending a full column to a const destination fails. Normalize const destinations once before appending.

### Release note

Fix block merge failures when scanner padding produces constant nullable columns.

### Check List (For Author)

- Test
    - Unit Test
@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?

@Gabriel39

Copy link
Copy Markdown
Contributor Author

run buildall

@Gabriel39

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Request changes: the merge-specific fix is sound, but the same const-representation mismatch remains in the functionally parallel MutableBlock row-append APIs; see the inline P1.

Critical checkpoint conclusions

  • Goal and data correctness: The new helper fixes the reported merge() and merge_ignore_overflow() failure for a live const-nullable destination, and the added unit test proves those two paths. The broader accumulation contract is not yet correct because add_row() and both add_rows() overloads can retain/reject per-block constants.
  • Scope and clarity: The patch is small and clear, but it is incomplete relative to the parallel MutableBlock append surface. A shared const-aware append abstraction would keep the fix focused and prevent the paths from diverging again.
  • Concurrency: No new shared state, thread entry, lock, atomic, or lock-order behavior is introduced. The examined mutable blocks are locally owned by their accumulation paths.
  • Lifecycle and COW: The changed merge helper is safe: recursive COW acquisition detaches shared owners, conversion constructs a new full column before assignment, and ScopedMutableBlock restores the replacement on normal, error, and exception exits. No static-initialization or ownership-cycle issue was found.
  • Configuration: No configuration item or dynamic-reload behavior is involved.
  • Compatibility: No symbol, protocol, storage-format, or rolling-upgrade compatibility change is involved.
  • Parallel paths: This is the blocking gap. clone_empty() preserves ColumnConst representation/value, while persistent partitioned-join and local-exchange accumulators call add_rows() directly. Later blocks can therefore fail or retain a stale per-block constant.
  • Conditional checks: The top-level is_column_const() check is necessary and consistent with the representation invariant; no speculative defensive branch was added.
  • Test coverage: The new BE unit test faithfully covers both merge wrappers, RAII restoration, row count, and null values. It needs companion coverage for repeated add_rows() calls with different constants and const sources.
  • Test results: No local build or test was run because this review environment explicitly prohibits builds. GitHub clang-format and CheckStyle checks passed. The macOS BE-UT job stopped before compilation/tests because the runner had Java 25 instead of required JDK 17; Linux BE-UT and compile checks were still running at review time.
  • Observability: No new logging or metric is needed for this local representation fix.
  • Transactions and persistence: No transaction, EditLog, replay, visibility-version, or persisted-state path is involved.
  • Data writes and crash behavior: No storage write/commit path is changed; the relevant correctness issue is in in-memory block accumulation.
  • FE-BE propagation: No new FE/BE variable, thrift field, or scattered send path is involved.
  • Performance: Destination materialization occurs only while the destination remains const and is required before full-column append. No additional hot-path regression was found, but the parallel-path fix should avoid repeatedly materializing the same owner.
  • Other issues: No additional distinct correctness, memory-safety, error-handling, nullable-shape, or test-result issue survived verification and convergence.

User focus

No additional user-provided focus was specified; the full PR and its upstream/downstream append paths were reviewed.

Comment thread be/src/core/block/block.h
DataTypes _data_types;
std::vector<std::string> _names;

void materialize_const_column(size_t position) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P1] Make the row-append APIs const-aware too

This helper is only called by the two merge paths, but MutableBlock::add_row() and both add_rows() overloads still append directly to _columns. Those destinations can also remain ColumnConst: for example, _partition_block() seeds a persistent buffer with in_block->clone_empty(), and ColumnConst::clone_resized(0) preserves the first block's nested value. After the first append, a later valid block with the same type but a different constant value is rejected by ColumnConst::insert_indices_from() (and a full source is also rejected by the sibling append methods). Please extend the shared append handling so both the destination and any const source are materialized, or are otherwise handled without assuming one per-block value persists across later blocks, and cover two add_rows() calls with different constants. Otherwise the same representation mismatch still breaks partitioned-join/local-exchange accumulation.

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17642	4084	4036	4036
q2	2048	332	202	202
q3	10382	1440	847	847
q4	4683	470	341	341
q5	7490	847	577	577
q6	179	177	137	137
q7	752	833	629	629
q8	9367	1584	1541	1541
q9	5839	4389	4379	4379
q10	6761	1793	1484	1484
q11	527	371	332	332
q12	743	615	451	451
q13	18118	3448	2829	2829
q14	266	269	240	240
q15	q16	787	774	719	719
q17	946	925	915	915
q18	7026	5771	5495	5495
q19	1304	1316	1103	1103
q20	812	659	558	558
q21	6037	2580	2383	2383
q22	441	343	291	291
Total cold run time: 102150 ms
Total hot run time: 29489 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4386	4279	4324	4279
q2	289	316	215	215
q3	4615	4935	4459	4459
q4	2063	2155	1371	1371
q5	4423	4254	4268	4254
q6	230	171	124	124
q7	1751	1957	1831	1831
q8	2546	2205	2203	2203
q9	8100	8161	7840	7840
q10	4670	4615	4181	4181
q11	584	441	395	395
q12	734	765	536	536
q13	3309	3602	2917	2917
q14	302	304	287	287
q15	q16	712	732	657	657
q17	1380	1301	1360	1301
q18	7956	7306	7316	7306
q19	1197	1147	1116	1116
q20	2209	2198	1948	1948
q21	5284	4544	4420	4420
q22	503	438	403	403
Total cold run time: 57243 ms
Total hot run time: 52043 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 177854 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 63ebf970f0335a3eb350b1c1d1824a9fd5518de4, data reload: false

query5	4321	659	497	497
query6	464	222	202	202
query7	4855	603	374	374
query8	341	191	176	176
query9	8752	4070	4083	4070
query10	526	363	295	295
query11	5787	2404	2117	2117
query12	155	102	102	102
query13	1262	590	451	451
query14	6192	5266	4863	4863
query14_1	4210	4212	4170	4170
query15	222	217	177	177
query16	1053	526	453	453
query17	1112	723	565	565
query18	2466	464	336	336
query19	204	193	146	146
query20	110	108	103	103
query21	233	162	138	138
query22	13493	13475	13308	13308
query23	17503	16560	16069	16069
query23_1	16218	16204	16316	16204
query24	7808	1799	1291	1291
query24_1	1322	1298	1289	1289
query25	571	456	395	395
query26	1330	396	218	218
query27	2539	597	402	402
query28	4412	2007	2006	2006
query29	1106	634	505	505
query30	350	266	233	233
query31	1147	1114	995	995
query32	109	65	62	62
query33	576	339	264	264
query34	1181	1199	639	639
query35	824	823	689	689
query36	1190	1138	1067	1067
query37	162	112	94	94
query38	1883	1737	1636	1636
query39	890	890	868	868
query39_1	837	837	859	837
query40	261	169	146	146
query41	73	76	70	70
query42	97	93	94	93
query43	332	331	278	278
query44	1506	787	765	765
query45	214	201	174	174
query46	1085	1240	759	759
query47	2145	2060	2042	2042
query48	395	433	313	313
query49	593	452	319	319
query50	1102	426	328	328
query51	10738	10568	10658	10568
query52	87	93	81	81
query53	254	284	202	202
query54	303	228	215	215
query55	75	69	65	65
query56	320	311	294	294
query57	1317	1283	1219	1219
query58	291	261	247	247
query59	1591	1673	1386	1386
query60	304	278	273	273
query61	151	152	146	146
query62	554	502	431	431
query63	248	205	200	200
query64	2815	1044	878	878
query65	4709	4589	4637	4589
query66	1838	518	383	383
query67	28674	29250	29079	29079
query68	3206	1515	1027	1027
query69	416	317	282	282
query70	1166	974	944	944
query71	370	319	304	304
query72	3110	2781	2383	2383
query73	885	807	411	411
query74	5088	4950	4719	4719
query75	2691	2610	2144	2144
query76	2305	1227	750	750
query77	362	405	283	283
query78	12092	11936	11353	11353
query79	1356	1164	729	729
query80	659	576	479	479
query81	482	330	288	288
query82	569	163	125	125
query83	404	337	297	297
query84	285	164	136	136
query85	970	627	531	531
query86	362	331	279	279
query87	1857	1837	1747	1747
query88	3767	2792	2773	2773
query89	439	392	327	327
query90	1968	195	194	194
query91	204	196	168	168
query92	64	62	54	54
query93	1608	1586	947	947
query94	551	357	332	332
query95	791	522	459	459
query96	1076	861	341	341
query97	2677	2645	2486	2486
query98	222	211	210	210
query99	1109	1132	987	987
Total cold run time: 263320 ms
Total hot run time: 177854 ms

@hello-stephen

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

query1	0.01	0.01	0.01
query2	0.10	0.08	0.05
query3	0.26	0.14	0.13
query4	1.61	0.13	0.13
query5	0.23	0.24	0.22
query6	1.23	1.12	1.13
query7	0.04	0.01	0.00
query8	0.06	0.04	0.04
query9	0.38	0.33	0.31
query10	0.54	0.54	0.55
query11	0.19	0.13	0.13
query12	0.18	0.14	0.14
query13	0.45	0.47	0.46
query14	1.01	1.00	1.01
query15	0.60	0.60	0.62
query16	0.32	0.33	0.32
query17	1.12	1.13	1.08
query18	0.23	0.22	0.21
query19	2.00	1.96	2.00
query20	0.02	0.01	0.01
query21	15.42	0.23	0.15
query22	4.71	0.06	0.05
query23	16.13	0.31	0.12
query24	2.93	0.45	0.32
query25	0.12	0.06	0.05
query26	0.74	0.20	0.16
query27	0.06	0.03	0.05
query28	3.49	0.94	0.56
query29	12.48	4.17	3.28
query30	0.27	0.14	0.16
query31	2.77	0.58	0.31
query32	3.22	0.59	0.49
query33	3.19	3.15	3.25
query34	15.64	4.21	3.53
query35	3.50	3.52	3.48
query36	0.56	0.43	0.42
query37	0.09	0.07	0.07
query38	0.05	0.05	0.04
query39	0.04	0.04	0.04
query40	0.18	0.17	0.14
query41	0.08	0.03	0.03
query42	0.04	0.03	0.04
query43	0.04	0.04	0.03
Total cold run time: 96.33 s
Total hot run time: 25.08 s

@Gabriel39
Gabriel39 marked this pull request as ready for review July 17, 2026 15:07
@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (8/8) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 75.00% (30488/40651)
Line Coverage 59.18% (336252/568191)
Region Coverage 55.91% (282130/504587)
Branch Coverage 57.22% (125180/218782)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants