Skip to content

[opt](be) Avoid redundant column copies - #66436

Open
Mryange wants to merge 2 commits into
apache:masterfrom
Mryange:opt-reuse-column-storage
Open

[opt](be) Avoid redundant column copies#66436
Mryange wants to merge 2 commits into
apache:masterfrom
Mryange:opt-reuse-column-storage

Conversation

@Mryange

@Mryange Mryange commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Problem Summary: Several execution paths copied complete column data even though the source columns could remain immutable and rely on copy-on-write before later mutation. Reuse expression results and array offsets directly, publish scanner columns after validation, and let partition filtering create only the selected rows.

Release note

None

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

Related PR: apache#65367

Problem Summary: Several execution paths copied complete column data even though the source columns could remain immutable and rely on copy-on-write before later mutation. Reuse expression results and array offsets directly, publish scanner columns after validation, and let partition filtering create only the selected rows.

### Release note

None

### Check List (For Author)

- Test: Not run (build and test validation deferred)
- Behavior changed: No
- 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?

@Mryange

Mryange commented Aug 4, 2026

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.

Review opinion: no blocking issue found. The copy-elision changes are consistent with Doris's current recursive column COW contract, and the review converged with zero inline findings.

Critical checkpoint conclusions:

  • Goal and proof: the PR removes eager full-column, projection, partition-filter, array-offset, and IF-branch copies while preserving values, row counts, nullability, and destination type metadata. Existing core COW and affected feature suites cover the surrounding mechanisms, but this PR adds no focused ownership regression test.
  • Scope and clarity: the ten-file change is cohesive and limited to publishing immutable column owners, validating their shape, and deferring copies until an actual mutation.
  • Data correctness and errors: duplicate/reordered outputs remain visibly shared; block clear, filter, shrink, and scoped mutation detach before writing. New size/physical-shape invariants fail loudly, and no Status is newly ignored.
  • Concurrency and locks: multicast installs each consumer's block owner under its existing mutex before queue release. The patch adds no shared mutable state, lock scope, lock-order change, or deadlock surface.
  • Lifecycle and ownership: FileScanner's scoped destination restores every pre-publication error path and publishes all owners before clearing its separate source block. Schema-scanner async work is dependency-fenced. Array-map retains the source offsets owner, and recursive mutation detaches nested data, offsets, and null maps. Hive/Iceberg transformers consume blocks synchronously; sorted Iceberg owns only its filtered copy.
  • Configuration and observability: no configuration, dynamic-update behavior, metrics, or logging contract changes; no additional observability is needed for this ownership-only optimization.
  • Compatibility and parallel paths: the changed API is internal C++, all call sites were checked, and no FE/BE protocol, storage format, function symbol, or rolling-upgrade contract changes. Hive, Iceberg, MaxCompute, multicast, schema scan, load FileScanner, array-map, and IF paths were each traced through their downstream consumers.
  • Data writes, transactions, and persistence: partition masks still produce independent selected blocks for each writer, including zero/all/selective masks and writer rollover. Commit/close, transaction, and persistence behavior is unchanged.
  • Performance: the change removes eager full-data copies and performs return-new filtering only when sharing requires it; no new row-wise loop, pathological allocation loop, or heavy work under a lock was introduced.
  • Tests/results: no build or test was run by this review because the review prompt is static-only. GitHub's formatter and repository metadata checks are green; macOS BE UT was still in progress at final sweep. No test result is claimed here.
  • Additional user focus: none was provided, so the complete PR was reviewed without a narrower focus.

Review completion: one convergence round completed with three normal full-review sections and two separate risk-focused sections, all returning NO_NEW_VALUABLE_FINDINGS. The authoritative and final live thread sets contain no existing inline issue, and the final inline comment set is empty.

@Mryange

Mryange commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17756	4014	3883	3883
q2	2077	332	201	201
q3	10207	1388	794	794
q4	4676	466	337	337
q5	7535	838	565	565
q6	181	173	136	136
q7	759	802	606	606
q8	9321	1594	1522	1522
q9	5333	4096	4057	4057
q10	6760	1655	1367	1367
q11	514	356	331	331
q12	736	573	450	450
q13	18111	3304	2784	2784
q14	271	274	235	235
q15	q16	737	724	656	656
q17	919	1000	949	949
q18	6633	5579	5602	5579
q19	1217	1253	1035	1035
q20	808	652	577	577
q21	5609	2648	2387	2387
q22	435	360	299	299
Total cold run time: 100595 ms
Total hot run time: 28750 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4271	4178	4173	4173
q2	295	318	207	207
q3	4575	4969	4347	4347
q4	2130	2229	1421	1421
q5	4243	4090	4116	4090
q6	227	170	126	126
q7	1694	1589	1436	1436
q8	2551	2341	2128	2128
q9	7425	7351	7454	7351
q10	4382	4251	3856	3856
q11	565	400	376	376
q12	738	732	494	494
q13	3283	3500	2894	2894
q14	324	308	276	276
q15	q16	697	709	682	682
q17	1300	1269	1251	1251
q18	12098	11048	11805	11048
q19	1153	1114	1135	1114
q20	2292	2216	1929	1929
q21	5610	4841	4850	4841
q22	554	483	434	434
Total cold run time: 60407 ms
Total hot run time: 54474 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 165729 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 8fb55f6216a7a3488d6c136db49f24f9676a9b6a, data reload: false

query5	4317	587	449	449
query6	470	216	198	198
query7	4842	586	320	320
query8	323	167	145	145
query9	8784	4079	4038	4038
query10	488	335	297	297
query11	5807	2192	1956	1956
query12	150	97	92	92
query13	1245	603	417	417
query14	6052	4222	3937	3937
query14_1	3769	3755	3750	3750
query15	201	193	180	180
query16	991	457	431	431
query17	911	696	540	540
query18	2431	460	354	354
query19	203	183	143	143
query20	103	101	102	101
query21	233	157	136	136
query22	13035	13160	13672	13160
query23	16277	15552	14933	14933
query23_1	14768	14660	14554	14554
query24	7678	1716	1228	1228
query24_1	1251	1240	1219	1219
query25	555	455	386	386
query26	1314	371	222	222
query27	2569	630	392	392
query28	4560	2052	2030	2030
query29	1087	614	501	501
query30	342	266	230	230
query31	1165	1127	1043	1043
query32	112	64	63	63
query33	525	315	252	252
query34	1204	1119	633	633
query35	720	748	654	654
query36	792	788	705	705
query37	150	111	92	92
query38	1831	1759	1704	1704
query39	817	818	810	810
query39_1	781	778	778	778
query40	247	165	162	162
query41	68	68	68	68
query42	96	91	91	91
query43	320	317	270	270
query44	1391	772	776	772
query45	188	171	161	161
query46	1097	1225	747	747
query47	1577	1585	1453	1453
query48	407	426	309	309
query49	599	400	296	296
query50	1075	438	339	339
query51	10476	10479	10184	10184
query52	87	87	75	75
query53	257	279	196	196
query54	295	265	242	242
query55	75	73	67	67
query56	321	298	300	298
query57	1018	1034	931	931
query58	298	260	281	260
query59	1523	1641	1374	1374
query60	315	294	274	274
query61	172	171	174	171
query62	400	357	275	275
query63	228	187	196	187
query64	2847	1020	858	858
query65	3884	3814	3798	3798
query66	1816	463	348	348
query67	27640	27374	27112	27112
query68	3383	1551	979	979
query69	393	303	255	255
query70	854	789	763	763
query71	358	323	304	304
query72	3062	2758	2358	2358
query73	818	812	437	437
query74	4641	4521	4317	4317
query75	2369	2323	1990	1990
query76	2409	1139	770	770
query77	329	355	265	265
query78	11269	11139	10659	10659
query79	1375	1185	719	719
query80	793	538	466	466
query81	500	325	286	286
query82	614	176	132	132
query83	406	335	291	291
query84	332	162	134	134
query85	975	601	512	512
query86	372	237	206	206
query87	1968	1945	1841	1841
query88	3705	2812	2792	2792
query89	375	328	286	286
query90	1865	216	198	198
query91	203	193	164	164
query92	66	58	54	54
query93	1506	1589	1012	1012
query94	619	366	348	348
query95	797	514	468	468
query96	1055	818	365	365
query97	2423	2442	2321	2321
query98	193	183	183	183
query99	732	729	599	599
Total cold run time: 252424 ms
Total hot run time: 165729 ms

@hello-stephen

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

query1	0.00	0.00	0.00
query2	0.09	0.05	0.05
query3	0.25	0.14	0.13
query4	1.60	0.14	0.13
query5	0.24	0.22	0.22
query6	1.16	0.79	0.83
query7	0.03	0.01	0.00
query8	0.05	0.04	0.03
query9	0.37	0.32	0.31
query10	0.59	0.60	0.58
query11	0.19	0.13	0.14
query12	0.19	0.14	0.14
query13	0.46	0.46	0.47
query14	0.99	0.99	0.99
query15	0.61	0.58	0.59
query16	0.34	0.32	0.31
query17	1.11	1.09	1.08
query18	0.21	0.21	0.20
query19	2.07	1.91	1.98
query20	0.01	0.01	0.01
query21	15.44	0.22	0.14
query22	4.87	0.06	0.05
query23	16.14	0.30	0.11
query24	3.01	0.43	0.31
query25	0.13	0.05	0.03
query26	0.72	0.21	0.14
query27	0.04	0.04	0.03
query28	3.55	0.76	0.36
query29	12.47	3.99	3.18
query30	0.28	0.16	0.15
query31	2.77	0.57	0.31
query32	3.23	0.59	0.48
query33	3.21	3.21	3.18
query34	15.52	4.01	3.27
query35	3.22	3.20	3.23
query36	0.56	0.44	0.42
query37	0.10	0.06	0.07
query38	0.05	0.04	0.03
query39	0.03	0.04	0.03
query40	0.16	0.16	0.14
query41	0.10	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.03	0.03
Total cold run time: 96.24 s
Total hot run time: 23.76 s

### What problem does this PR solve?

Issue Number: None

Related PR: apache#65367

Problem Summary: Directly publishing file scanner expression results bypassed the insertion step that normalizes scalar Variant columns into destination Variant columns. Variant JSON stream loads therefore aborted on a physical column shape mismatch. Keep direct publication for matching column shapes and fall back to typed insertion when normalization is required.

### Release note

None

### Check List (For Author)

- Test: Not run (failure diagnosed from the inverted-index Variant stream-load regression log)
- Behavior changed: No
- Does this need documentation: No
@Mryange

Mryange commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17605	3993	3960	3960
q2	2040	330	219	219
q3	10409	1473	801	801
q4	4728	477	342	342
q5	7972	841	557	557
q6	252	171	136	136
q7	785	815	618	618
q8	10644	1638	1662	1638
q9	5819	4145	4096	4096
q10	6785	1637	1366	1366
q11	520	357	332	332
q12	746	575	462	462
q13	18087	3314	2785	2785
q14	266	257	237	237
q15	q16	761	730	653	653
q17	1038	975	980	975
q18	6670	5624	5600	5600
q19	1233	1256	959	959
q20	792	702	585	585
q21	5576	2673	2481	2481
q22	424	348	306	306
Total cold run time: 103152 ms
Total hot run time: 29108 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4438	4283	4282	4282
q2	285	333	215	215
q3	4691	5050	4414	4414
q4	2183	2243	1408	1408
q5	4278	4151	4173	4151
q6	223	174	128	128
q7	1699	2051	1656	1656
q8	2484	2107	2015	2015
q9	7324	7341	7277	7277
q10	4400	4278	3852	3852
q11	572	396	364	364
q12	731	715	519	519
q13	3452	3577	2933	2933
q14	307	316	289	289
q15	q16	724	763	663	663
q17	1332	1266	1286	1266
q18	12146	10999	11908	10999
q19	1169	1135	1123	1123
q20	2247	2214	1926	1926
q21	5793	4700	4516	4516
q22	493	440	398	398
Total cold run time: 60971 ms
Total hot run time: 54394 ms

@hello-stephen

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

query5	4350	597	449	449
query6	481	214	216	214
query7	4892	580	319	319
query8	324	169	149	149
query9	8746	4091	4067	4067
query10	491	349	286	286
query11	5856	2203	1996	1996
query12	157	127	99	99
query13	1233	606	405	405
query14	6048	4296	3993	3993
query14_1	3783	3784	3849	3784
query15	202	192	185	185
query16	992	474	454	454
query17	901	697	518	518
query18	2437	456	340	340
query19	203	186	151	151
query20	103	99	100	99
query21	238	157	140	140
query22	13084	13062	12824	12824
query23	15787	15021	14630	14630
query23_1	14676	14671	14795	14671
query24	7527	1673	1250	1250
query24_1	1243	1256	1228	1228
query25	548	443	399	399
query26	1389	367	220	220
query27	2475	601	411	411
query28	4533	2120	2069	2069
query29	1093	646	495	495
query30	348	258	223	223
query31	1176	1128	1073	1073
query32	108	62	61	61
query33	532	325	266	266
query34	1216	1152	664	664
query35	744	757	656	656
query36	780	782	728	728
query37	157	112	100	100
query38	1878	1771	1672	1672
query39	823	832	820	820
query39_1	771	799	791	791
query40	266	172	147	147
query41	71	69	69	69
query42	101	96	97	96
query43	327	323	285	285
query44	1473	796	798	796
query45	191	179	174	174
query46	1069	1260	752	752
query47	1570	1573	1492	1492
query48	407	440	308	308
query49	587	417	310	310
query50	1065	428	335	335
query51	10348	10353	10229	10229
query52	89	89	78	78
query53	260	280	210	210
query54	294	268	221	221
query55	75	70	66	66
query56	322	287	281	281
query57	1030	985	917	917
query58	284	253	267	253
query59	1558	1608	1361	1361
query60	299	275	252	252
query61	145	141	145	141
query62	406	315	263	263
query63	234	200	200	200
query64	2790	1026	886	886
query65	3902	3818	3849	3818
query66	1855	462	361	361
query67	27152	27235	27151	27151
query68	3052	1618	959	959
query69	404	295	270	270
query70	913	799	767	767
query71	365	336	329	329
query72	3006	2593	2255	2255
query73	869	776	450	450
query74	4597	4494	4322	4322
query75	2360	2354	1990	1990
query76	2334	1142	787	787
query77	347	375	280	280
query78	11207	11165	10627	10627
query79	1465	1155	780	780
query80	1283	533	476	476
query81	538	323	282	282
query82	639	181	147	147
query83	403	325	299	299
query84	325	160	130	130
query85	990	624	524	524
query86	405	244	218	218
query87	1987	1975	1816	1816
query88	3807	2831	2828	2828
query89	410	329	289	289
query90	1881	199	203	199
query91	198	184	165	165
query92	63	61	56	56
query93	1630	1507	947	947
query94	720	346	334	334
query95	799	583	484	484
query96	1081	792	349	349
query97	2456	2454	2351	2351
query98	197	189	182	182
query99	749	730	603	603
Total cold run time: 252191 ms
Total hot run time: 165665 ms

@hello-stephen

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

query1	0.01	0.01	0.01
query2	0.09	0.06	0.05
query3	0.25	0.14	0.13
query4	1.61	0.14	0.15
query5	0.24	0.22	0.22
query6	1.16	0.81	0.81
query7	0.03	0.02	0.01
query8	0.06	0.04	0.04
query9	0.39	0.32	0.32
query10	0.57	0.60	0.55
query11	0.19	0.13	0.13
query12	0.18	0.15	0.15
query13	0.47	0.47	0.46
query14	1.02	1.00	1.00
query15	0.63	0.59	0.59
query16	0.31	0.31	0.32
query17	1.13	1.09	1.15
query18	0.22	0.22	0.21
query19	2.06	1.94	1.96
query20	0.02	0.02	0.01
query21	15.42	0.26	0.14
query22	4.71	0.09	0.06
query23	16.07	0.31	0.12
query24	2.91	0.44	0.31
query25	0.11	0.05	0.04
query26	0.74	0.20	0.15
query27	0.03	0.04	0.03
query28	3.50	0.83	0.34
query29	12.47	4.15	3.26
query30	0.28	0.15	0.15
query31	2.76	0.58	0.32
query32	3.22	0.59	0.51
query33	3.20	3.19	3.17
query34	15.64	4.13	3.30
query35	3.26	3.24	3.24
query36	0.56	0.43	0.43
query37	0.09	0.07	0.07
query38	0.06	0.04	0.04
query39	0.03	0.04	0.03
query40	0.17	0.15	0.15
query41	0.09	0.03	0.03
query42	0.04	0.03	0.03
query43	0.05	0.03	0.03
Total cold run time: 96.05 s
Total hot run time: 24.12 s

column_ptr = make_nullable(column_ptr);
}
mutable_output_columns[j]->insert_range_from(*column_ptr, 0, rows);
DORIS_CHECK_EQ(column_ptr->size(), rows);

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.

这个代码,你找文强确认一下,你确定这个直接用名字等于这个方式靠谱吗。很多那种列的这个名字,可能都是一些默认值,或者一些其他东西,这种我感觉容易翻车

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.

3 participants