Skip to content

[Optimization](array) Avoid materializing const array columns in element_at#64175

Open
HappenLee wants to merge 2 commits into
apache:masterfrom
HappenLee:array_opt
Open

[Optimization](array) Avoid materializing const array columns in element_at#64175
HappenLee wants to merge 2 commits into
apache:masterfrom
HappenLee:array_opt

Conversation

@HappenLee
Copy link
Copy Markdown
Contributor

Summary

  • Skip convert_to_full_column_if_const() for the array argument in element_at when it's a ColumnConst, using unpack_if_const() + index_check_const() instead to avoid O(N) memory expansion.
  • Add is_const_array parameter to _execute_nullable, _execute_number, _execute_string, and _execute_common methods.
  • Add unit tests covering const int32/string arrays, null arrays, null indices, and large batches (4096 rows).

Test plan

  • BE UT: function_array_element_test.cpp — 5 new test cases covering const array scenarios.

🤖 Generated with Claude Code

…ent_at (apache#64039)

When the array argument to element_at is a ColumnConst (e.g. a literal
array repeated across rows), skip convert_to_full_column_if_const() and
use index_check_const() instead. This avoids O(N) memory expansion for
the array column.

Add unit tests covering const int32/string arrays, null arrays, null
indices, and large batches.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@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?

@HappenLee
Copy link
Copy Markdown
Contributor Author

/review

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.

Reviewed the PR and found no blocking issues.

Critical checkpoint conclusions:

  • Goal and proof: The change avoids materializing constant array arguments in element_at while preserving row-wise results via index_check_const; added BE unit coverage targets const int32/string arrays, null array, null index, and large batches.
  • Scope and clarity: The implementation is focused on the array path and leaves the map path behavior unchanged where row-aligned offsets are still needed.
  • Concurrency: Not applicable; this is per-block function execution with no shared mutable state or new threads.
  • Lifecycle/static initialization: Not applicable; no static/global lifecycle-sensitive objects were added.
  • Configuration/compatibility: Not applicable; no config, storage format, or FE-BE protocol changes.
  • Parallel paths: Map lookup path is intentionally unchanged; array numeric/string/common paths were updated consistently.
  • Null handling/data correctness: Reviewed nullable array, nullable index, nested nullable elements, positive/negative/out-of-range indices, and const-array row mapping; behavior appears consistent with existing semantics.
  • Tests: Targeted tests were added for the optimized const-array scenarios. I attempted to run ./run-be-ut.sh --run --filter=function_array_element_test.*, but this runner failed during gensrc setup because thirdparty/installed/bin/protoc was missing, before compiling the test.
  • Observability/transactions/persistence: Not applicable for this local vectorized function optimization.
  • Performance: The change removes the O(N) materialization for const array inputs without introducing obvious redundant work in hot paths.

User focus: No additional user-provided review focus was present.

@HappenLee
Copy link
Copy Markdown
Contributor Author

run buildall

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@HappenLee
Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 56.90% (33/58) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 53.79% (21065/39165)
Line Coverage 37.47% (200223/534363)
Region Coverage 33.47% (156898/468739)
Branch Coverage 34.53% (68688/198927)

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-H: Total hot run time: 28968 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit c2b5391ec66489948490113b7549247029fb2f94, 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	17725	4061	3996	3996
q2	q3	10776	1387	792	792
q4	4678	486	341	341
q5	7518	880	590	590
q6	193	179	138	138
q7	769	825	646	646
q8	9921	1614	1540	1540
q9	6596	4467	4469	4467
q10	6841	1884	1571	1571
q11	445	285	257	257
q12	636	432	303	303
q13	18134	3381	2761	2761
q14	265	257	236	236
q15	q16	824	779	702	702
q17	935	953	979	953
q18	6909	5714	5629	5629
q19	1598	1248	1008	1008
q20	505	410	271	271
q21	5919	2598	2459	2459
q22	433	357	308	308
Total cold run time: 101620 ms
Total hot run time: 28968 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	4317	4236	4225	4225
q2	q3	4468	4985	4337	4337
q4	2076	2176	1381	1381
q5	4410	4266	4297	4266
q6	222	173	128	128
q7	1724	1763	1800	1763
q8	2511	2208	2151	2151
q9	7901	7855	7832	7832
q10	4799	4753	4271	4271
q11	611	436	381	381
q12	739	766	564	564
q13	3481	3633	2964	2964
q14	324	310	291	291
q15	q16	749	741	678	678
q17	1342	1321	1326	1321
q18	7947	7457	7042	7042
q19	1106	1093	1104	1093
q20	2212	2225	1929	1929
q21	5272	4549	4371	4371
q22	531	487	415	415
Total cold run time: 56742 ms
Total hot run time: 51403 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

TPC-DS: Total hot run time: 169028 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 c2b5391ec66489948490113b7549247029fb2f94, data reload: false

query5	4324	626	483	483
query6	437	203	182	182
query7	4837	558	284	284
query8	365	209	222	209
query9	8764	3979	3989	3979
query10	445	320	251	251
query11	5860	2347	2183	2183
query12	153	104	95	95
query13	1246	583	415	415
query14	6398	5435	5069	5069
query14_1	4412	4376	4357	4357
query15	203	196	170	170
query16	963	436	385	385
query17	1094	696	545	545
query18	2419	477	340	340
query19	194	176	140	140
query20	115	105	104	104
query21	210	133	111	111
query22	13585	13515	13563	13515
query23	17382	16440	16139	16139
query23_1	16298	16302	16247	16247
query24	7716	1767	1314	1314
query24_1	1299	1295	1307	1295
query25	546	442	382	382
query26	1314	311	175	175
query27	2649	582	342	342
query28	4485	2018	2006	2006
query29	1098	619	518	518
query30	323	241	208	208
query31	1124	1074	966	966
query32	113	64	65	64
query33	525	325	253	253
query34	1183	1128	677	677
query35	774	787	679	679
query36	1400	1368	1247	1247
query37	156	107	95	95
query38	3191	3153	3050	3050
query39	925	929	892	892
query39_1	873	872	869	869
query40	224	130	106	106
query41	72	67	74	67
query42	98	96	97	96
query43	331	328	288	288
query44	
query45	206	193	183	183
query46	1089	1160	741	741
query47	2451	2361	2334	2334
query48	421	380	296	296
query49	649	487	378	378
query50	1011	358	249	249
query51	4329	4307	4278	4278
query52	91	90	81	81
query53	242	268	189	189
query54	280	231	211	211
query55	83	78	72	72
query56	278	246	227	227
query57	1452	1392	1311	1311
query58	257	223	218	218
query59	1549	1660	1425	1425
query60	295	257	244	244
query61	215	155	155	155
query62	704	652	594	594
query63	235	186	184	184
query64	2548	767	612	612
query65	
query66	1795	465	350	350
query67	29825	29613	29540	29540
query68	
query69	420	302	261	261
query70	968	964	921	921
query71	300	226	212	212
query72	2915	2647	2625	2625
query73	827	788	449	449
query74	5150	4959	4789	4789
query75	2650	2569	2232	2232
query76	2310	1139	763	763
query77	348	388	293	293
query78	12377	12405	11824	11824
query79	1649	1034	757	757
query80	1247	470	391	391
query81	532	290	240	240
query82	596	161	128	128
query83	317	268	244	244
query84	
query85	918	530	442	442
query86	415	285	280	280
query87	3422	3428	3172	3172
query88	3676	2736	2713	2713
query89	431	383	331	331
query90	1842	177	174	174
query91	180	161	138	138
query92	63	62	54	54
query93	1601	1418	896	896
query94	713	363	268	268
query95	688	465	339	339
query96	1083	741	364	364
query97	2680	2696	2554	2554
query98	212	206	201	201
query99	1142	1184	1044	1044
Total cold run time: 252182 ms
Total hot run time: 169028 ms

@hello-stephen
Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (58/58) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.76% (28223/38261)
Line Coverage 57.76% (306885/531318)
Region Coverage 54.62% (257225/470944)
Branch Coverage 56.00% (111562/199210)

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