Skip to content

[opt](expr) vectorize nullable comparison predicates - #66688

Open
Mryange wants to merge 2 commits into
apache:masterfrom
Mryange:optimize-nullable-comparison-predicate
Open

[opt](expr) vectorize nullable comparison predicates#66688
Mryange wants to merge 2 commits into
apache:masterfrom
Mryange:optimize-nullable-comparison-predicate

Conversation

@Mryange

@Mryange Mryange commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Nullable comparison predicates used short-circuit && to combine the null map and comparison result. With ColumnElementView, Clang generated a scalar loop instead of SIMD instructions.

This PR uses bitwise & for the two boolean operands, preserving the result while allowing vectorization. It also adds a focused comparison predicate benchmark.

Assembly changes from scalar cmp/test operations per row to vectorized vpcmpgtd and vpand operations over multiple rows.

Isolated second predicate Before After Improvement
4096 rows, 4.5% null 1.188 ns/row 0.393 ns/row 3.02x
8192 rows, 4.5% null 0.857 ns/row 0.393 ns/row 2.18x

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: None

Problem Summary: Nullable comparison predicate loops used short-circuit logical AND when combining the null map with the comparison result. This prevented SIMD code generation for ColumnElementView inputs. Use bitwise AND on boolean operands so Clang can vectorize both assign and AND predicate paths. The isolated second-predicate benchmark improves from 1.188 to 0.393 ns/row for 4096-row batches and from 0.857 to 0.393 ns/row for 8192-row batches.

### Release note

None

### Check List (For Author)

- Test: Manual test

    - Built benchmark_test with sh build.sh --benchmark -j48 and ran focused comparison predicate benchmarks.

- Behavior changed: No

- Does this need documentation: No
Issue Number: None

Related PR: None

Problem Summary: Add a Doris-only benchmark for comparison predicate evaluation across nullable layouts, predicate combinations, profile-scope selection compaction, and code-generation variants.

None

- Test: Manual test

    - Built benchmark_test with sh build.sh --benchmark -j48 and ran focused production and code-generation cases.

- 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 12, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17660	3972	3982	3972
q2	2049	331	202	202
q3	10254	1330	786	786
q4	4678	461	339	339
q5	7502	822	541	541
q6	179	169	138	138
q7	741	788	612	612
q8	9431	1634	1618	1618
q9	5673	4069	4011	4011
q10	6810	1619	1348	1348
q11	513	343	325	325
q12	738	562	448	448
q13	18087	3235	2720	2720
q14	266	251	235	235
q15	q16	727	720	653	653
q17	970	912	942	912
q18	6603	5598	5521	5521
q19	1154	1208	1027	1027
q20	806	670	591	591
q21	5640	2548	2465	2465
q22	432	357	301	301
Total cold run time: 100913 ms
Total hot run time: 28765 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4304	4262	4285	4262
q2	271	305	201	201
q3	4475	4892	4370	4370
q4	2163	2237	1402	1402
q5	4227	4051	4133	4051
q6	229	176	126	126
q7	1638	1605	1367	1367
q8	2520	2230	2051	2051
q9	7219	7135	7238	7135
q10	4278	4241	3867	3867
q11	550	404	366	366
q12	707	720	499	499
q13	3211	3496	3059	3059
q14	282	301	268	268
q15	q16	731	703	622	622
q17	1291	1274	1304	1274
q18	12181	11042	11871	11042
q19	1174	1137	1144	1137
q20	2213	2249	1964	1964
q21	5633	4907	4905	4905
q22	544	508	403	403
Total cold run time: 59841 ms
Total hot run time: 54371 ms

@hello-stephen

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

query5	4329	588	434	434
query6	460	242	203	203
query7	4888	536	323	323
query8	328	166	145	145
query9	8757	3845	3803	3803
query10	492	359	295	295
query11	5808	2190	2021	2021
query12	146	94	93	93
query13	1275	587	418	418
query14	6108	4287	4103	4103
query14_1	3822	3859	3843	3843
query15	201	189	176	176
query16	973	446	404	404
query17	918	658	538	538
query18	2413	456	345	345
query19	210	189	149	149
query20	103	102	112	102
query21	236	160	137	137
query22	13086	13074	12824	12824
query23	15634	14924	14442	14442
query23_1	14611	14662	14600	14600
query24	7577	1715	1251	1251
query24_1	1244	1269	1250	1250
query25	574	457	397	397
query26	1336	348	201	201
query27	2624	597	379	379
query28	4543	1861	1866	1861
query29	1067	616	478	478
query30	355	262	222	222
query31	1189	1112	1046	1046
query32	111	65	62	62
query33	528	309	259	259
query34	1158	1097	610	610
query35	737	742	645	645
query36	782	788	674	674
query37	162	113	100	100
query38	1836	1778	1690	1690
query39	820	838	804	804
query39_1	790	783	796	783
query40	263	168	153	153
query41	71	69	68	68
query42	94	93	93	93
query43	331	323	279	279
query44	1395	730	745	730
query45	187	172	174	172
query46	1067	1152	727	727
query47	1525	1505	1458	1458
query48	371	410	283	283
query49	593	406	306	306
query50	1119	416	332	332
query51	10310	10726	10205	10205
query52	87	89	78	78
query53	255	279	197	197
query54	300	248	235	235
query55	80	73	69	69
query56	317	299	320	299
query57	1022	997	928	928
query58	303	269	290	269
query59	1541	1561	1376	1376
query60	321	285	268	268
query61	180	175	170	170
query62	444	322	269	269
query63	245	200	195	195
query64	2863	1033	827	827
query65	3857	3837	3815	3815
query66	1851	487	365	365
query67	20071	19888	19947	19888
query68	3290	1547	998	998
query69	407	297	251	251
query70	871	810	784	784
query71	364	342	307	307
query72	3033	2658	1858	1858
query73	807	818	413	413
query74	4660	4508	4293	4293
query75	2367	2334	1986	1986
query76	2349	1135	769	769
query77	348	373	274	274
query78	11014	11147	10691	10691
query79	1332	1123	754	754
query80	1248	539	454	454
query81	511	333	290	290
query82	632	175	143	143
query83	384	338	288	288
query84	324	158	130	130
query85	981	575	533	533
query86	380	240	228	228
query87	2007	1959	1838	1838
query88	3279	2432	2455	2432
query89	399	320	285	285
query90	1929	203	194	194
query91	202	187	162	162
query92	62	65	60	60
query93	1575	1526	959	959
query94	673	367	293	293
query95	784	525	476	476
query96	962	737	322	322
query97	2468	2448	2314	2314
query98	195	189	182	182
query99	741	730	604	604
Total cold run time: 243977 ms
Total hot run time: 156824 ms

@hello-stephen

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

query1	0.01	0.00	0.01
query2	0.08	0.04	0.05
query3	0.25	0.14	0.13
query4	1.61	0.14	0.14
query5	0.25	0.22	0.22
query6	1.17	0.81	0.84
query7	0.04	0.00	0.00
query8	0.05	0.04	0.03
query9	0.38	0.30	0.32
query10	0.55	0.59	0.55
query11	0.19	0.14	0.14
query12	0.18	0.14	0.14
query13	0.46	0.47	0.47
query14	1.00	0.97	0.99
query15	0.61	0.63	0.58
query16	0.30	0.33	0.33
query17	1.06	1.13	1.12
query18	0.23	0.21	0.21
query19	2.02	1.99	2.03
query20	0.02	0.01	0.01
query21	15.48	0.22	0.13
query22	4.92	0.06	0.06
query23	16.15	0.33	0.12
query24	2.90	0.44	0.33
query25	0.11	0.05	0.04
query26	0.72	0.21	0.16
query27	0.04	0.05	0.03
query28	3.49	0.82	0.36
query29	12.46	4.01	3.19
query30	0.27	0.15	0.15
query31	2.77	0.57	0.32
query32	3.22	0.58	0.49
query33	3.15	3.23	3.28
query34	15.59	3.92	3.29
query35	3.24	3.23	3.20
query36	0.55	0.41	0.42
query37	0.10	0.06	0.07
query38	0.05	0.04	0.03
query39	0.04	0.04	0.04
query40	0.16	0.15	0.15
query41	0.08	0.03	0.02
query42	0.03	0.03	0.03
query43	0.04	0.03	0.04
Total cold run time: 96.02 s
Total hot run time: 24.05 s

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