Skip to content

[fix](varaint) Preserve variant sub-path order - #67803

Merged
morrySnow merged 1 commit into
apache:masterfrom
morrySnow:fix/variant-subpath-order
Sep 11, 2026
Merged

[fix](varaint) Preserve variant sub-path order#67803
morrySnow merged 1 commit into
apache:masterfrom
morrySnow:fix/variant-subpath-order

Conversation

@morrySnow

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Problem Summary:

When nested-column pruning was disabled, a multi-level VARIANT access could return different values from the regular and constant branches of a UNION ALL. For example, with {"a":{"b":1},"b":{"a":2}}, selecting c['a']['b'] returned 1 from the table branch but 2 from the constant branch.

The pruning context stores sub-paths in canonical root-to-leaf order, such as [a, b]. The UNION constant-expression rewrite and the project pushdown rewrite rebuilt nested ElementAt expressions by iterating those paths backwards, producing c['b']['a'].

This change centralizes construction of nested ElementAt expressions and applies each canonical sub-path from root to leaf. It uses the same helper for UNION constant expressions and projected VARIANT expressions so extraction and reconstruction share one order contract.

The regression test reproduces the UNION result mismatch with nested-column pruning disabled, covers the projected-expression path, and verifies the enabled-pruning control case.

Release note

Fix incorrect values for multi-level VARIANT sub-paths in UNION ALL constant branches.

Check List (For Author)

  • Test:
    • Unit Test: PruneNestedColumnTest (62 tests)
    • Regression Test: variant_p0/test_variant_sub_path_order
    • Full FE build
  • Behavior changed: Yes. Multi-level VARIANT sub-paths now preserve SQL access order across rewritten branches.
  • Does this need documentation: No

### What problem does this PR solve?

Problem Summary:
Multi-level VARIANT sub-paths are represented in canonical root-to-leaf order. Two rewrite paths rebuilt ElementAt expressions in reverse order, so a UNION ALL constant branch could read a different nested value when nested-column pruning was disabled.

The change centralizes root-to-leaf ElementAt construction and uses it for UNION constant expressions and projected VARIANT expressions. Unit coverage checks the construction/extraction invariant, and regression coverage verifies UNION and project plans with nested-column pruning both disabled and enabled.

### Release note

Fix incorrect values for multi-level VARIANT sub-paths in UNION ALL constant branches.

### Check List (For Author)

- Test: Unit Test and Regression Test
- Behavior changed: Yes. Multi-level VARIANT sub-paths now preserve SQL access order across rewritten branches.
- 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 Author

run buildall

@morrySnow morrySnow changed the title [fix](nereids) Preserve variant sub-path order [fix](varaint) Preserve variant sub-path order Sep 10, 2026
@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17644	3055	3031	3031
q2	2143	258	226	226
q3	10211	953	512	512
q4	4675	253	207	207
q5	7670	574	393	393
q6	139	115	94	94
q7	538	505	390	390
q8	9230	843	925	843
q9	3516	2438	2433	2433
q10	6522	851	716	716
q11	394	195	184	184
q12	627	264	203	203
q13	18148	1589	1173	1173
q14	160	152	137	137
q15	q16	442	401	372	372
q17	1350	889	856	856
q18	3156	2314	2305	2305
q19	1261	884	796	796
q20	371	282	205	205
q21	5646	1703	1850	1703
q22	340	272	230	230
Total cold run time: 94183 ms
Total hot run time: 17009 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3416	3348	3333	3333
q2	522	395	378	378
q3	2368	2332	2174	2174
q4	1200	1178	919	919
q5	2195	2154	2131	2131
q6	164	119	87	87
q7	1088	931	896	896
q8	1603	1405	1417	1405
q9	3180	3157	3137	3137
q10	1913	1810	1647	1647
q11	364	282	250	250
q12	452	434	350	350
q13	1497	1544	1159	1159
q14	175	182	163	163
q15	q16	401	400	360	360
q17	3678	3409	3316	3316
q18	4932	4537	5023	4537
q19	963	878	865	865
q20	1046	995	844	844
q21	3855	3181	3192	3181
q22	398	359	319	319
Total cold run time: 35410 ms
Total hot run time: 31451 ms

@hello-stephen

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

query5	4247	413	341	341
query6	380	136	123	123
query7	4948	411	229	229
query8	290	127	122	122
query9	8696	2922	2904	2904
query10	409	219	183	183
query11	5370	1060	940	940
query12	118	73	74	73
query13	1191	439	309	309
query14	6150	2231	2124	2124
query14_1	2014	2008	2015	2008
query15	177	121	118	118
query16	925	392	369	369
query17	814	476	378	378
query18	2330	335	244	244
query19	169	146	113	113
query20	80	75	73	73
query21	204	103	93	93
query22	5498	5459	5342	5342
query23	6844	6395	6203	6203
query23_1	6107	6366	6053	6053
query24	7270	1098	778	778
query24_1	788	801	799	799
query25	430	305	236	236
query26	1221	235	121	121
query27	2788	425	249	249
query28	4693	1496	1509	1496
query29	906	431	329	329
query30	246	155	131	131
query31	813	404	331	331
query32	124	73	70	70
query33	456	217	165	165
query34	988	843	485	485
query35	416	405	343	343
query36	563	578	534	534
query37	115	78	71	71
query38	1011	861	823	823
query39	504	479	500	479
query39_1	451	480	504	480
query40	195	90	78	78
query41	54	52	52	52
query42	75	77	73	73
query43	243	243	213	213
query44	981	538	543	538
query45	115	105	105	105
query46	785	817	529	529
query47	770	756	698	698
query48	316	294	243	243
query49	536	234	187	187
query50	725	262	202	202
query51	8353	8251	8147	8147
query52	68	67	62	62
query53	195	198	148	148
query54	228	178	142	142
query55	79	67	67	67
query56	185	175	173	173
query57	734	681	629	629
query58	217	164	165	164
query59	1231	1244	1113	1113
query60	244	180	173	173
query61	110	135	122	122
query62	362	202	170	170
query63	173	144	139	139
query64	2682	835	727	727
query65	1657	1625	1611	1611
query66	1803	268	211	211
query67	10001	9804	9731	9731
query68	2906	1221	743	743
query69	338	225	203	203
query70	678	603	617	603
query71	254	180	159	159
query72	2293	1695	1510	1510
query73	639	569	342	342
query74	1890	1244	1160	1160
query75	1177	1107	986	986
query76	2288	703	540	540
query77	249	272	218	218
query78	4038	3900	3254	3254
query79	2848	846	588	588
query80	1565	327	278	278
query81	515	161	134	134
query82	624	125	99	99
query83	282	207	191	191
query84	293	111	88	88
query85	809	331	277	277
query86	468	177	172	172
query87	1036	983	911	911
query88	2975	2123	2114	2114
query89	292	200	179	179
query90	2084	128	131	128
query91	129	118	93	93
query92	93	71	65	65
query93	2034	1236	679	679
query94	644	257	224	224
query95	525	256	302	256
query96	794	563	273	273
query97	1063	1076	1004	1004
query98	174	138	138	138
query99	424	359	307	307
Total cold run time: 179683 ms
Total hot run time: 82826 ms

@hello-stephen

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

query1	0.00	0.00	0.00
query2	0.07	0.04	0.04
query3	0.25	0.10	0.11
query4	1.61	0.11	0.11
query5	0.18	0.15	0.16
query6	1.25	0.67	0.72
query7	0.03	0.00	0.01
query8	0.04	0.03	0.03
query9	0.28	0.22	0.21
query10	0.34	0.33	0.35
query11	0.16	0.12	0.12
query12	0.15	0.12	0.12
query13	0.32	0.32	0.30
query14	0.45	0.47	0.46
query15	0.38	0.36	0.36
query16	0.24	0.22	0.26
query17	0.73	0.77	0.70
query18	0.18	0.16	0.16
query19	1.25	1.17	1.18
query20	0.02	0.01	0.01
query21	15.48	0.16	0.12
query22	5.08	0.04	0.05
query23	16.18	0.24	0.10
query24	3.00	0.33	0.25
query25	0.09	0.05	0.03
query26	0.81	0.18	0.12
query27	0.04	0.04	0.02
query28	3.68	0.55	0.27
query29	12.43	3.18	2.57
query30	0.25	0.11	0.12
query31	2.76	0.38	0.17
query32	3.52	0.32	0.23
query33	1.40	1.41	1.47
query34	15.39	2.19	1.78
query35	1.78	1.76	1.74
query36	0.47	0.29	0.29
query37	0.06	0.04	0.04
query38	0.05	0.03	0.03
query39	0.03	0.03	0.03
query40	0.12	0.09	0.07
query41	0.08	0.03	0.02
query42	0.03	0.03	0.02
query43	0.03	0.03	0.03
Total cold run time: 90.69 s
Total hot run time: 14.75 s

@morrySnow
morrySnow merged commit 742defc into apache:master Sep 11, 2026
41 of 43 checks passed
@morrySnow
morrySnow deleted the fix/variant-subpath-order branch September 11, 2026 07:12
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