Skip to content

Conversation

@yujun777
Copy link
Contributor

@yujun777 yujun777 commented Oct 9, 2025

for a boolean data type case when expression, if all its when clauses' result are true / false literal, then can rewrite this case when to AND / OR expression.

for example:

case when a = 1 then true when b = 1 then false else c = 1 end   
rewrite to:  (a = 1) <=> true  or (not((b = 1) <=> true) and c = 1)

if (a = 1, true,  b = 1) 
rewrite to:  (a=1) <=> true or b = 1

then later, there are other rules will opt ' xxx <=> true', 'xxx = true'.

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

@hello-stephen
Copy link
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?

@yujun777
Copy link
Contributor Author

yujun777 commented Oct 9, 2025

run buildall

@yujun777 yujun777 changed the title [feat](nereids) eliminate case when expression if all its branch are true/false [feat](nereids) eliminate case when expression if all its branch are true/false literal Oct 9, 2025
@doris-robot
Copy link

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

query1	0.05	0.05	0.05
query2	0.09	0.06	0.06
query3	0.26	0.08	0.08
query4	1.61	0.12	0.12
query5	0.30	0.27	0.25
query6	1.18	0.67	0.67
query7	0.03	0.02	0.02
query8	0.06	0.05	0.05
query9	0.65	0.54	0.51
query10	0.57	0.57	0.59
query11	0.17	0.11	0.11
query12	0.15	0.12	0.13
query13	0.64	0.62	0.62
query14	1.03	1.03	1.03
query15	0.88	0.87	0.85
query16	0.42	0.41	0.41
query17	1.07	1.08	1.08
query18	0.22	0.20	0.20
query19	1.97	1.87	1.85
query20	0.02	0.02	0.02
query21	15.42	0.94	0.58
query22	0.79	1.18	0.68
query23	14.89	1.43	0.67
query24	6.61	1.94	1.02
query25	0.51	0.17	0.14
query26	0.55	0.16	0.14
query27	0.07	0.06	0.05
query28	9.92	1.38	0.94
query29	12.61	3.93	3.26
query30	0.29	0.13	0.11
query31	2.82	0.60	0.39
query32	3.24	0.57	0.49
query33	3.09	3.06	3.18
query34	16.10	5.48	4.83
query35	4.97	4.90	4.94
query36	0.68	0.54	0.50
query37	0.10	0.08	0.08
query38	0.06	0.04	0.04
query39	0.03	0.03	0.03
query40	0.16	0.15	0.15
query41	0.09	0.03	0.03
query42	0.04	0.03	0.03
query43	0.05	0.04	0.04
Total cold run time: 104.46 s
Total hot run time: 30.83 s

@yujun777
Copy link
Contributor Author

yujun777 commented Oct 9, 2025

run buildall

@yujun777 yujun777 force-pushed the eliminate-case-when-for-boolean-literal branch from 27c1884 to e9380a2 Compare October 9, 2025 13:01
@doris-robot
Copy link

TPC-DS: Total hot run time: 190543 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 27c1884ced25645e6660c9003326cdf4abf9443e, data reload: false

query1	1041	429	396	396
query2	6577	1711	1674	1674
query3	6754	226	220	220
query4	26390	23667	23414	23414
query5	5515	636	490	490
query6	341	244	216	216
query7	4666	517	291	291
query8	323	259	262	259
query9	8687	2589	2584	2584
query10	512	342	284	284
query11	16163	15140	14841	14841
query12	185	123	117	117
query13	1679	551	431	431
query14	11497	9181	9254	9181
query15	221	195	175	175
query16	8718	695	570	570
query17	1689	870	704	704
query18	2197	503	407	407
query19	243	242	216	216
query20	154	145	180	145
query21	273	139	120	120
query22	5087	5118	4885	4885
query23	34842	33938	33854	33854
query24	8590	2456	2436	2436
query25	584	534	457	457
query26	1434	278	164	164
query27	2777	532	394	394
query28	4637	2259	2208	2208
query29	892	647	501	501
query30	322	250	216	216
query31	959	837	776	776
query32	88	86	80	80
query33	588	404	319	319
query34	801	869	515	515
query35	796	827	741	741
query36	972	996	954	954
query37	128	115	89	89
query38	3485	3594	3488	3488
query39	1483	1401	1406	1401
query40	218	124	118	118
query41	63	59	58	58
query42	118	115	110	110
query43	471	508	464	464
query44	1351	816	834	816
query45	184	181	172	172
query46	830	1003	626	626
query47	1770	1832	1772	1772
query48	415	419	316	316
query49	774	503	406	406
query50	640	684	412	412
query51	3927	3945	3927	3927
query52	114	116	101	101
query53	237	264	191	191
query54	602	594	541	541
query55	94	82	83	82
query56	349	333	319	319
query57	1192	1200	1119	1119
query58	290	279	272	272
query59	2573	2644	2539	2539
query60	353	345	333	333
query61	170	156	156	156
query62	806	758	659	659
query63	227	191	199	191
query64	4472	1207	842	842
query65	4058	3962	3936	3936
query66	1096	423	336	336
query67	15446	15358	15217	15217
query68	9678	961	594	594
query69	512	322	292	292
query70	1357	1363	1226	1226
query71	546	332	325	325
query72	6071	4870	4814	4814
query73	699	561	357	357
query74	9327	8894	8626	8626
query75	4590	3344	2874	2874
query76	4005	1149	751	751
query77	1033	402	325	325
query78	9654	9657	8880	8880
query79	5236	846	574	574
query80	730	577	529	529
query81	488	355	236	236
query82	391	166	138	138
query83	284	268	255	255
query84	312	108	97	97
query85	901	469	518	469
query86	362	297	290	290
query87	3760	3794	3707	3707
query88	2952	2250	2240	2240
query89	442	325	293	293
query90	2058	226	220	220
query91	167	163	137	137
query92	89	65	67	65
query93	3511	981	642	642
query94	708	430	336	336
query95	400	329	328	328
query96	499	570	287	287
query97	2919	2991	2890	2890
query98	230	209	209	209
query99	1443	1436	1293	1293
Total cold run time: 290484 ms
Total hot run time: 190543 ms

@doris-robot
Copy link

ClickBench: Total hot run time: 30.13 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 27c1884ced25645e6660c9003326cdf4abf9443e, data reload: false

query1	0.06	0.05	0.05
query2	0.09	0.05	0.06
query3	0.25	0.08	0.08
query4	1.61	0.12	0.11
query5	0.27	0.28	0.25
query6	1.17	0.65	0.66
query7	0.03	0.04	0.03
query8	0.06	0.05	0.04
query9	0.60	0.52	0.52
query10	0.60	0.59	0.57
query11	0.16	0.11	0.11
query12	0.16	0.12	0.12
query13	0.62	0.62	0.63
query14	1.05	1.05	1.02
query15	0.85	0.84	0.86
query16	0.40	0.40	0.38
query17	1.07	1.02	1.10
query18	0.22	0.20	0.20
query19	1.96	1.86	1.86
query20	0.02	0.01	0.02
query21	15.42	0.96	0.57
query22	0.78	1.26	0.75
query23	14.80	1.38	0.64
query24	7.01	1.33	0.40
query25	0.50	0.28	0.07
query26	0.58	0.17	0.14
query27	0.07	0.05	0.05
query28	8.98	1.39	0.93
query29	12.59	3.93	3.28
query30	0.28	0.14	0.12
query31	2.83	0.60	0.39
query32	3.25	0.59	0.49
query33	3.04	3.19	3.10
query34	16.13	5.49	4.86
query35	4.87	4.92	4.95
query36	0.71	0.52	0.51
query37	0.10	0.08	0.08
query38	0.06	0.05	0.04
query39	0.04	0.02	0.03
query40	0.18	0.15	0.14
query41	0.09	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.04	0.04
Total cold run time: 103.64 s
Total hot run time: 30.13 s

@yujun777 yujun777 changed the title [feat](nereids) eliminate case when expression if all its branch are true/false literal [feat](case when) eliminate case when expression if all its branch are true/false literal Oct 9, 2025
@yujun777 yujun777 force-pushed the eliminate-case-when-for-boolean-literal branch from e9380a2 to 630b7b8 Compare October 9, 2025 15:27
@yujun777 yujun777 changed the title [feat](case when) eliminate case when expression if all its branch are true/false literal [feat](case when) rewrite case when to compound predicate Oct 13, 2025
@yujun777
Copy link
Contributor Author

run buildall

2 similar comments
@yujun777
Copy link
Contributor Author

run buildall

@yujun777
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

ClickBench: Total hot run time: 30.67 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 373fa19f5d1753818c52dda30bc5328acefcd693, data reload: false

query1	0.06	0.05	0.05
query2	0.09	0.05	0.06
query3	0.25	0.08	0.08
query4	1.61	0.12	0.11
query5	0.28	0.27	0.25
query6	1.18	0.66	0.66
query7	0.03	0.02	0.02
query8	0.06	0.05	0.05
query9	0.65	0.53	0.53
query10	0.57	0.58	0.58
query11	0.16	0.11	0.12
query12	0.15	0.11	0.12
query13	0.63	0.62	0.63
query14	1.04	1.05	1.03
query15	0.87	0.86	0.87
query16	0.39	0.40	0.43
query17	1.09	1.10	1.08
query18	0.22	0.21	0.21
query19	1.99	1.89	1.90
query20	0.01	0.02	0.02
query21	15.42	0.93	0.57
query22	0.76	1.11	0.64
query23	15.04	1.42	0.66
query24	6.79	1.16	0.78
query25	0.49	0.34	0.07
query26	0.58	0.16	0.13
query27	0.07	0.06	0.06
query28	9.68	1.37	0.95
query29	12.66	3.92	3.30
query30	0.28	0.14	0.12
query31	2.84	0.60	0.40
query32	3.24	0.56	0.48
query33	3.11	3.11	3.14
query34	16.01	5.50	4.94
query35	4.93	4.94	4.88
query36	0.70	0.51	0.50
query37	0.10	0.07	0.07
query38	0.06	0.04	0.05
query39	0.04	0.03	0.03
query40	0.18	0.16	0.15
query41	0.09	0.04	0.03
query42	0.04	0.02	0.02
query43	0.04	0.04	0.03
Total cold run time: 104.48 s
Total hot run time: 30.67 s

@yujun777 yujun777 force-pushed the eliminate-case-when-for-boolean-literal branch from 373fa19 to b4b1650 Compare October 13, 2025 06:24
@yujun777
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

query1	0.06	0.05	0.05
query2	0.09	0.05	0.06
query3	0.25	0.09	0.08
query4	1.61	0.12	0.12
query5	0.27	0.28	0.24
query6	1.15	0.65	0.64
query7	0.04	0.03	0.03
query8	0.06	0.05	0.05
query9	0.64	0.53	0.51
query10	0.60	0.57	0.58
query11	0.17	0.11	0.12
query12	0.15	0.13	0.12
query13	0.64	0.62	0.61
query14	1.04	1.04	1.03
query15	0.87	0.88	0.87
query16	0.41	0.41	0.40
query17	1.04	1.02	1.04
query18	0.21	0.20	0.20
query19	1.97	1.86	1.86
query20	0.02	0.02	0.02
query21	15.45	0.93	0.58
query22	0.77	1.44	0.78
query23	14.74	1.43	0.66
query24	7.77	0.81	0.93
query25	0.47	0.32	0.18
query26	0.67	0.16	0.14
query27	0.07	0.06	0.06
query28	9.00	1.41	0.93
query29	12.60	3.99	3.32
query30	0.28	0.14	0.11
query31	2.82	0.62	0.39
query32	3.23	0.57	0.49
query33	3.07	3.12	3.14
query34	16.23	5.62	4.85
query35	4.98	4.89	4.90
query36	0.68	0.53	0.51
query37	0.11	0.07	0.07
query38	0.07	0.05	0.04
query39	0.03	0.04	0.03
query40	0.17	0.14	0.14
query41	0.09	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.04	0.04
Total cold run time: 104.67 s
Total hot run time: 30.78 s

@yujun777
Copy link
Contributor Author

run buildall

@yujun777
Copy link
Contributor Author

run p0

@yujun777
Copy link
Contributor Author

run cloud_p0

@yujun777
Copy link
Contributor Author

run nonConcurrent

@yujun777
Copy link
Contributor Author

run vault_p0

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 94.00% (47/50) 🎉
Increment coverage report
Complete coverage report

@doris-robot
Copy link

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

query1	0.06	0.05	0.04
query2	0.09	0.06	0.06
query3	0.26	0.09	0.09
query4	1.61	0.12	0.12
query5	0.29	0.27	0.25
query6	1.18	0.65	0.64
query7	0.04	0.04	0.03
query8	0.06	0.05	0.05
query9	0.65	0.55	0.52
query10	0.58	0.58	0.58
query11	0.17	0.11	0.12
query12	0.16	0.12	0.12
query13	0.63	0.62	0.62
query14	1.06	1.03	1.05
query15	0.87	0.87	0.86
query16	0.42	0.40	0.41
query17	1.06	1.05	1.06
query18	0.22	0.20	0.20
query19	1.93	1.86	1.81
query20	0.02	0.02	0.01
query21	15.45	0.92	0.59
query22	0.78	1.13	0.60
query23	15.08	1.43	0.64
query24	6.97	2.09	0.60
query25	0.47	0.26	0.10
query26	0.52	0.16	0.14
query27	0.07	0.06	0.05
query28	9.54	1.45	0.95
query29	12.55	4.05	3.29
query30	0.28	0.14	0.13
query31	2.83	0.64	0.39
query32	3.26	0.57	0.48
query33	3.20	3.11	3.16
query34	16.24	5.59	4.89
query35	4.99	4.93	4.98
query36	0.68	0.52	0.53
query37	0.10	0.08	0.07
query38	0.07	0.04	0.04
query39	0.04	0.03	0.03
query40	0.18	0.15	0.16
query41	0.09	0.04	0.03
query42	0.03	0.03	0.03
query43	0.04	0.04	0.03
Total cold run time: 104.82 s
Total hot run time: 30.38 s

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 94.00% (47/50) 🎉
Increment coverage report
Complete coverage report

1 similar comment
@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 94.00% (47/50) 🎉
Increment coverage report
Complete coverage report

@yujun777 yujun777 force-pushed the eliminate-case-when-for-boolean-literal branch from b4b1650 to 87ce88c Compare October 14, 2025 08:42
@yujun777
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

TPC-DS: Total hot run time: 190849 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 87ce88cb0a819ab7dcfa0b9e0308f520803c9ea5, data reload: false

query1	1075	444	403	403
query2	6573	1700	1697	1697
query3	6777	226	233	226
query4	26412	23737	23447	23447
query5	5100	673	490	490
query6	360	256	247	247
query7	4658	491	315	315
query8	326	275	270	270
query9	8735	2612	2574	2574
query10	543	361	288	288
query11	15382	15058	14941	14941
query12	183	117	115	115
query13	1682	543	424	424
query14	11402	9330	9236	9236
query15	245	195	176	176
query16	7656	655	492	492
query17	1355	734	629	629
query18	2053	459	381	381
query19	229	218	187	187
query20	143	139	136	136
query21	227	136	119	119
query22	4789	4702	4565	4565
query23	34799	33970	34039	33970
query24	9163	2560	2527	2527
query25	614	602	535	535
query26	1625	295	165	165
query27	2893	541	387	387
query28	4449	2217	2180	2180
query29	851	662	535	535
query30	318	260	228	228
query31	944	916	789	789
query32	96	82	69	69
query33	611	371	333	333
query34	799	871	511	511
query35	784	844	742	742
query36	986	1019	907	907
query37	123	105	85	85
query38	3571	3630	3605	3605
query39	1482	1396	1397	1396
query40	220	124	118	118
query41	65	59	60	59
query42	121	116	110	110
query43	489	498	463	463
query44	1342	820	833	820
query45	183	181	173	173
query46	831	992	636	636
query47	1764	1784	1707	1707
query48	406	415	305	305
query49	770	488	415	415
query50	644	705	407	407
query51	3900	3894	3883	3883
query52	110	109	99	99
query53	249	275	198	198
query54	607	585	532	532
query55	89	89	89	89
query56	333	329	327	327
query57	1191	1209	1127	1127
query58	291	279	273	273
query59	2499	2578	2505	2505
query60	355	350	336	336
query61	161	158	157	157
query62	791	749	679	679
query63	232	207	199	199
query64	4396	1183	833	833
query65	4057	3995	3948	3948
query66	1091	433	343	343
query67	15777	15343	15172	15172
query68	9616	953	598	598
query69	490	324	309	309
query70	1386	1330	1291	1291
query71	517	343	316	316
query72	5775	4802	4767	4767
query73	693	560	357	357
query74	9207	9166	8808	8808
query75	4581	3392	2852	2852
query76	4388	1167	757	757
query77	1023	418	320	320
query78	9536	9837	8915	8915
query79	3147	841	615	615
query80	694	566	593	566
query81	499	269	230	230
query82	247	161	130	130
query83	303	274	257	257
query84	302	121	94	94
query85	868	477	413	413
query86	334	327	314	314
query87	3875	3777	3727	3727
query88	2899	2250	2254	2250
query89	431	333	317	317
query90	2127	226	233	226
query91	161	166	138	138
query92	89	71	71	71
query93	2287	1008	644	644
query94	689	454	333	333
query95	411	328	318	318
query96	492	557	284	284
query97	2932	3002	2888	2888
query98	241	220	218	218
query99	1439	1400	1291	1291
Total cold run time: 284656 ms
Total hot run time: 190849 ms

@doris-robot
Copy link

ClickBench: Total hot run time: 30.88 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 87ce88cb0a819ab7dcfa0b9e0308f520803c9ea5, data reload: false

query1	0.05	0.05	0.05
query2	0.10	0.05	0.06
query3	0.26	0.08	0.08
query4	1.61	0.12	0.13
query5	0.27	0.27	0.25
query6	1.17	0.65	0.65
query7	0.02	0.03	0.02
query8	0.06	0.05	0.05
query9	0.64	0.52	0.52
query10	0.58	0.61	0.59
query11	0.17	0.11	0.11
query12	0.15	0.12	0.12
query13	0.64	0.63	0.62
query14	1.05	1.02	1.03
query15	0.88	0.86	0.88
query16	0.40	0.40	0.41
query17	1.01	1.08	1.05
query18	0.22	0.20	0.21
query19	1.95	1.84	1.84
query20	0.02	0.02	0.01
query21	15.44	0.91	0.59
query22	0.76	1.27	0.66
query23	14.89	1.35	0.63
query24	7.18	1.36	1.07
query25	0.49	0.09	0.19
query26	0.69	0.15	0.14
query27	0.08	0.05	0.06
query28	8.94	1.32	0.95
query29	12.58	3.94	3.25
query30	0.29	0.14	0.14
query31	2.84	0.60	0.39
query32	3.25	0.56	0.48
query33	3.05	3.11	3.20
query34	16.15	5.43	4.92
query35	4.93	4.93	4.95
query36	0.70	0.53	0.51
query37	0.10	0.07	0.08
query38	0.07	0.05	0.04
query39	0.04	0.03	0.02
query40	0.18	0.14	0.14
query41	0.08	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.03	0.04
Total cold run time: 104.06 s
Total hot run time: 30.88 s

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 94.00% (47/50) 🎉
Increment coverage report
Complete coverage report

@yujun777
Copy link
Contributor Author

run cloud_p0

@hello-stephen
Copy link
Contributor

FE Regression Coverage Report

Increment line coverage 94.00% (47/50) 🎉
Increment coverage report
Complete coverage report

@englefly
Copy link
Contributor

这个优化没有明显的优化点, 相反可能会降低效率. 因为在BE端我们对if 有很多优化,但 <=> 没有.

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Oct 16, 2025
@github-actions
Copy link
Contributor

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

@yujun777
Copy link
Contributor Author

这个优化没有明显的优化点, 相反可能会降低效率. 因为在BE端我们对if 有很多优化,但 <=> 没有.

if (a = b, true, c = d) => a = b or c = d, 这

@morrySnow morrySnow merged commit 58203c8 into apache:master Oct 16, 2025
27 of 28 checks passed
yujun777 added a commit to yujun777/doris that referenced this pull request Nov 20, 2025
for a boolean data type case when expression, if all its when clauses'
result are true / false literal, then can rewrite this case when to AND
/ OR expression.

for example:

case when a = 1 then true when b = 1 then false else c = 1 end
rewrite to:  (a = 1) <=> true  or (not((b = 1) <=> true) and c = 1)

if (a = 1, true,  b = 1)
rewrite to:  (a=1) <=> true or b = 1
yujun777 added a commit to yujun777/doris that referenced this pull request Dec 1, 2025
for a boolean data type case when expression, if all its when clauses'
result are true / false literal, then can rewrite this case when to AND
/ OR expression.

for example:

case when a = 1 then true when b = 1 then false else c = 1 end
rewrite to:  (a = 1) <=> true  or (not((b = 1) <=> true) and c = 1)

if (a = 1, true,  b = 1)
rewrite to:  (a=1) <=> true or b = 1
yujun777 added a commit to yujun777/doris that referenced this pull request Dec 2, 2025
for a boolean data type case when expression, if all its when clauses'
result are true / false literal, then can rewrite this case when to AND
/ OR expression.

for example:

case when a = 1 then true when b = 1 then false else c = 1 end
rewrite to:  (a = 1) <=> true  or (not((b = 1) <=> true) and c = 1)

if (a = 1, true,  b = 1)
rewrite to:  (a=1) <=> true or b = 1
yujun777 added a commit to yujun777/doris that referenced this pull request Dec 8, 2025
for a boolean data type case when expression, if all its when clauses'
result are true / false literal, then can rewrite this case when to AND
/ OR expression.

for example:

case when a = 1 then true when b = 1 then false else c = 1 end
rewrite to:  (a = 1) <=> true  or (not((b = 1) <=> true) and c = 1)

if (a = 1, true,  b = 1)
rewrite to:  (a=1) <=> true or b = 1
yujun777 added a commit to yujun777/doris that referenced this pull request Jan 9, 2026
for a boolean data type case when expression, if all its when clauses'
result are true / false literal, then can rewrite this case when to AND
/ OR expression.

for example:

case when a = 1 then true when b = 1 then false else c = 1 end
rewrite to:  (a = 1) <=> true  or (not((b = 1) <=> true) and c = 1)

if (a = 1, true,  b = 1)
rewrite to:  (a=1) <=> true or b = 1
yujun777 added a commit to yujun777/doris that referenced this pull request Jan 12, 2026
for a boolean data type case when expression, if all its when clauses'
result are true / false literal, then can rewrite this case when to AND
/ OR expression.

for example:

case when a = 1 then true when b = 1 then false else c = 1 end
rewrite to:  (a = 1) <=> true  or (not((b = 1) <=> true) and c = 1)

if (a = 1, true,  b = 1)
rewrite to:  (a=1) <=> true or b = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants