Skip to content

Conversation

@feiniaofeiafei
Copy link
Contributor

@feiniaofeiafei feiniaofeiafei commented Mar 27, 2025

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #32878 #49473

Problem Summary:

 SELECT
    IF(
        t.`gender` IN (''),
        (
            TIMESTAMPDIFF(
                YEAR,
                NOW(),
                NOW()
            )
        ),
        1
    ) AS x0,
    TIMESTAMPDIFF(
        YEAR,
        NOW(),
        NOW()
    ) AS x1
FROM
t1 AS t
GROUP BY
    x0,
    x1;

after EliminateGroupByConstant, this sql will be rewritten to

 SELECT
    IF(
        t.`gender` IN (''),
        0,
        1
    ) AS x0,
    0 AS x1
FROM
t1 AS t
GROUP BY
     IF(
        t.`gender` IN (''),
        (
            TIMESTAMPDIFF(
                YEAR,
                NOW(),
                NOW()
            )
        ),
        1
    ) ;

The select expression and the group by expression is different, and will report error in normalizeagg.

The fix in PR #49473 may introduce another issue. Consider the following query:

SELECT func2(100) FROM t GROUP BY func1(), func2(func1());

If func1() can be constant-folded to 100, then func2(func1()) will be replaced with func2(100), allowing the query to execute successfully. However, when func1() cannot be folded to 100, the query will fail. This creates an inconsistent behavior where query execution depends on whether func1() can be constant-folded or not, which is not an ideal implementation.

To address this issue, this PR modifies the normalizeAgg logic to eliminate constant group by keys. With this change, the query will consistently fail regardless of whether func1() can be folded or not, ensuring more predictable behavior.

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

@Thearas
Copy link
Contributor

Thearas commented Mar 27, 2025

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?

@feiniaofeiafei feiniaofeiafei force-pushed the fix_eliminate_group_by_constant2 branch from 9c60d8c to 2f21632 Compare March 27, 2025 11:17
@feiniaofeiafei
Copy link
Contributor Author

run buildall

@morrySnow morrySnow added usercase Important user case type label dev/2.1.x dev/3.0.x labels Mar 27, 2025
@morrySnow morrySnow marked this pull request as draft March 27, 2025 11:21
@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	26128	5088	4997	4997
q2	2062	297	160	160
q3	10395	1209	671	671
q4	10241	1001	529	529
q5	7548	2435	2376	2376
q6	184	164	129	129
q7	931	754	602	602
q8	9295	1291	1101	1101
q9	6847	5184	5200	5184
q10	6805	2327	1900	1900
q11	476	281	268	268
q12	350	357	224	224
q13	17781	3686	3185	3185
q14	229	239	210	210
q15	537	480	491	480
q16	616	610	582	582
q17	573	834	369	369
q18	7671	7246	7233	7233
q19	1225	955	561	561
q20	329	326	195	195
q21	3811	3310	2372	2372
q22	1074	1037	967	967
Total cold run time: 115108 ms
Total hot run time: 34295 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5101	5072	5059	5059
q2	241	324	238	238
q3	2144	2671	2299	2299
q4	1400	1779	1367	1367
q5	4507	4456	4398	4398
q6	211	167	132	132
q7	2003	1939	1768	1768
q8	2662	2673	2562	2562
q9	7285	7307	7163	7163
q10	2961	3191	2720	2720
q11	572	499	495	495
q12	689	765	610	610
q13	3530	3870	3292	3292
q14	304	312	264	264
q15	519	466	484	466
q16	667	705	670	670
q17	1145	1559	1365	1365
q18	7760	7736	7595	7595
q19	808	771	813	771
q20	1935	1960	1899	1899
q21	5311	4758	4740	4740
q22	1083	1074	1009	1009
Total cold run time: 52838 ms
Total hot run time: 50882 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 194092 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 2f2163224eb27b9f6c022f96aec52ab9b6655ac8, data reload: false

query1	1382	1072	1037	1037
query2	6105	2034	1939	1939
query3	11029	4629	4570	4570
query4	57596	24602	23477	23477
query5	5098	505	469	469
query6	358	200	178	178
query7	4909	495	269	269
query8	303	253	227	227
query9	5859	2535	2568	2535
query10	431	319	264	264
query11	15261	15117	15101	15101
query12	153	106	103	103
query13	1049	504	405	405
query14	10088	6400	6419	6400
query15	201	207	185	185
query16	7246	671	516	516
query17	1101	727	559	559
query18	1774	415	336	336
query19	190	192	171	171
query20	129	123	118	118
query21	203	125	104	104
query22	4504	4664	4366	4366
query23	34054	33284	33465	33284
query24	6437	2419	2409	2409
query25	479	474	401	401
query26	697	277	150	150
query27	2269	500	324	324
query28	3148	2499	2434	2434
query29	613	595	455	455
query30	287	228	200	200
query31	865	892	811	811
query32	75	73	68	68
query33	481	380	332	332
query34	768	844	512	512
query35	804	843	771	771
query36	962	1040	932	932
query37	123	102	77	77
query38	4077	4401	4100	4100
query39	1527	1464	1468	1464
query40	224	127	114	114
query41	62	64	64	64
query42	129	117	115	115
query43	535	527	483	483
query44	1315	811	825	811
query45	188	180	168	168
query46	861	1053	669	669
query47	1871	1849	1882	1849
query48	391	428	315	315
query49	717	532	441	441
query50	726	738	423	423
query51	4253	4388	4288	4288
query52	116	103	103	103
query53	220	257	182	182
query54	487	501	423	423
query55	85	89	81	81
query56	280	272	280	272
query57	1175	1202	1126	1126
query58	251	260	244	244
query59	2805	2965	2907	2907
query60	298	324	263	263
query61	134	132	132	132
query62	728	774	678	678
query63	221	197	185	185
query64	1882	1042	702	702
query65	4423	4355	4276	4276
query66	718	399	303	303
query67	15832	15832	15576	15576
query68	8076	816	516	516
query69	540	295	266	266
query70	1222	1124	1082	1082
query71	489	293	259	259
query72	5851	4757	4635	4635
query73	1419	568	339	339
query74	9258	9114	9177	9114
query75	3769	3247	2734	2734
query76	4294	1187	748	748
query77	607	375	292	292
query78	9966	10220	9366	9366
query79	2032	814	564	564
query80	751	522	435	435
query81	481	252	218	218
query82	443	123	94	94
query83	312	172	206	172
query84	288	91	83	83
query85	792	356	335	335
query86	387	300	292	292
query87	4407	4473	4388	4388
query88	3092	2207	2217	2207
query89	402	318	286	286
query90	1951	207	201	201
query91	150	143	116	116
query92	75	63	58	58
query93	1167	1068	594	594
query94	693	409	304	304
query95	350	272	261	261
query96	487	575	277	277
query97	3217	3223	3139	3139
query98	221	206	206	206
query99	1476	1411	1265	1265
Total cold run time: 302227 ms
Total hot run time: 194092 ms

@doris-robot
Copy link

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

query1	0.04	0.04	0.03
query2	0.12	0.10	0.10
query3	0.25	0.19	0.19
query4	1.59	0.19	0.20
query5	0.60	0.56	0.59
query6	1.19	0.72	0.73
query7	0.03	0.02	0.01
query8	0.04	0.03	0.03
query9	0.56	0.53	0.53
query10	0.57	0.59	0.58
query11	0.15	0.10	0.11
query12	0.14	0.11	0.11
query13	0.61	0.60	0.60
query14	2.65	2.68	2.71
query15	0.94	0.85	0.83
query16	0.38	0.38	0.40
query17	1.04	1.02	1.01
query18	0.22	0.20	0.20
query19	1.89	1.85	1.95
query20	0.01	0.01	0.02
query21	15.37	0.90	0.56
query22	0.76	1.15	0.70
query23	14.99	1.34	0.58
query24	6.79	1.92	0.63
query25	0.49	0.17	0.05
query26	0.57	0.16	0.13
query27	0.06	0.05	0.05
query28	10.26	0.91	0.43
query29	12.57	3.94	3.29
query30	0.24	0.08	0.07
query31	2.84	0.59	0.37
query32	3.22	0.54	0.48
query33	3.00	3.07	3.06
query34	15.80	5.11	4.52
query35	4.53	4.50	4.54
query36	0.67	0.51	0.48
query37	0.08	0.06	0.06
query38	0.05	0.05	0.03
query39	0.03	0.03	0.02
query40	0.16	0.15	0.13
query41	0.09	0.03	0.02
query42	0.04	0.02	0.02
query43	0.04	0.02	0.02
Total cold run time: 105.67 s
Total hot run time: 30.91 s

@feiniaofeiafei feiniaofeiafei force-pushed the fix_eliminate_group_by_constant2 branch 2 times, most recently from 1503f10 to 2627106 Compare March 28, 2025 03:57
@feiniaofeiafei
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	25839	5154	5070	5070
q2	2070	285	170	170
q3	10415	1236	721	721
q4	10216	999	539	539
q5	7531	2366	2361	2361
q6	193	170	132	132
q7	899	746	611	611
q8	9311	1244	1008	1008
q9	6938	5181	5138	5138
q10	6813	2325	1916	1916
q11	480	279	259	259
q12	342	358	224	224
q13	17782	3662	3118	3118
q14	233	221	204	204
q15	560	502	496	496
q16	640	608	585	585
q17	562	863	340	340
q18	7657	7371	7074	7074
q19	1213	966	550	550
q20	332	324	189	189
q21	3858	3281	2355	2355
q22	1059	1043	992	992
Total cold run time: 114943 ms
Total hot run time: 34052 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5511	5160	5210	5160
q2	230	320	227	227
q3	2128	2680	2311	2311
q4	1400	1816	1409	1409
q5	4464	4417	4403	4403
q6	217	174	133	133
q7	2052	1971	1811	1811
q8	2517	2598	2555	2555
q9	7294	7091	7160	7091
q10	2991	3194	2759	2759
q11	586	520	499	499
q12	731	761	638	638
q13	3521	4010	3359	3359
q14	291	287	287	287
q15	552	488	492	488
q16	647	673	659	659
q17	1165	1556	1397	1397
q18	7741	7496	7501	7496
q19	796	761	840	761
q20	1957	2037	1957	1957
q21	5357	4861	4792	4792
q22	1116	1069	1067	1067
Total cold run time: 53264 ms
Total hot run time: 51259 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 193420 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 2627106200d0df6b9669f2124f86a61066ac6ead, data reload: false

query1	1354	1085	1088	1085
query2	6171	1974	1934	1934
query3	11157	4665	4424	4424
query4	59238	25550	23334	23334
query5	4866	512	510	510
query6	382	196	193	193
query7	4933	513	275	275
query8	332	253	241	241
query9	6510	2548	2573	2548
query10	437	310	257	257
query11	15542	15102	14929	14929
query12	165	110	119	110
query13	1072	507	432	432
query14	10697	6413	6452	6413
query15	214	191	179	179
query16	7116	681	534	534
query17	1078	744	579	579
query18	1582	411	329	329
query19	193	184	159	159
query20	129	123	119	119
query21	213	120	108	108
query22	4654	4748	4542	4542
query23	33832	33602	33550	33550
query24	6021	2436	2424	2424
query25	456	490	393	393
query26	706	269	145	145
query27	2014	475	325	325
query28	2795	2447	2485	2447
query29	598	555	428	428
query30	287	222	202	202
query31	879	879	795	795
query32	76	59	64	59
query33	440	376	322	322
query34	774	872	519	519
query35	811	894	788	788
query36	957	1004	930	930
query37	120	102	97	97
query38	4115	4379	4273	4273
query39	1494	1439	1521	1439
query40	219	136	111	111
query41	61	63	92	63
query42	120	109	109	109
query43	508	516	476	476
query44	1348	862	835	835
query45	190	173	167	167
query46	877	1037	650	650
query47	1859	1918	1797	1797
query48	391	444	302	302
query49	702	506	418	418
query50	706	728	411	411
query51	4187	4209	4263	4209
query52	108	112	98	98
query53	223	256	176	176
query54	486	494	404	404
query55	82	82	81	81
query56	266	271	265	265
query57	1112	1142	1094	1094
query58	233	235	238	235
query59	2595	2743	2685	2685
query60	296	274	250	250
query61	121	127	126	126
query62	714	751	672	672
query63	218	181	180	180
query64	1477	1003	658	658
query65	4312	4260	4299	4260
query66	745	392	298	298
query67	15881	15798	15288	15288
query68	7732	882	510	510
query69	563	350	258	258
query70	1279	1135	1101	1101
query71	508	292	274	274
query72	5666	4746	4751	4746
query73	1343	632	348	348
query74	9362	9145	8734	8734
query75	3868	3253	2754	2754
query76	4426	1194	769	769
query77	618	369	283	283
query78	10046	10120	9348	9348
query79	6318	831	554	554
query80	765	592	462	462
query81	471	260	224	224
query82	723	130	103	103
query83	271	179	160	160
query84	284	99	74	74
query85	746	358	305	305
query86	378	318	293	293
query87	4462	4622	4449	4449
query88	2895	2251	2212	2212
query89	450	311	287	287
query90	2021	211	221	211
query91	146	144	111	111
query92	78	69	58	58
query93	3470	1074	577	577
query94	705	414	316	316
query95	358	274	270	270
query96	487	556	277	277
query97	3186	3216	3185	3185
query98	221	201	198	198
query99	1408	1446	1281	1281
Total cold run time: 309701 ms
Total hot run time: 193420 ms

@doris-robot
Copy link

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

query1	0.04	0.04	0.02
query2	0.13	0.10	0.10
query3	0.26	0.19	0.18
query4	1.59	0.19	0.19
query5	0.59	0.57	0.60
query6	1.18	0.72	0.72
query7	0.02	0.02	0.02
query8	0.04	0.04	0.03
query9	0.58	0.53	0.51
query10	0.57	0.60	0.57
query11	0.16	0.10	0.11
query12	0.15	0.11	0.12
query13	0.62	0.60	0.61
query14	2.80	2.69	2.68
query15	0.94	0.86	0.85
query16	0.38	0.38	0.39
query17	1.05	1.03	1.05
query18	0.23	0.20	0.20
query19	1.93	1.98	1.89
query20	0.01	0.01	0.02
query21	15.38	0.91	0.53
query22	0.76	1.05	0.66
query23	15.04	1.36	0.62
query24	7.45	1.89	0.41
query25	0.28	0.10	0.07
query26	0.67	0.17	0.14
query27	0.05	0.04	0.04
query28	8.96	0.90	0.44
query29	12.54	4.13	3.36
query30	0.25	0.09	0.06
query31	2.82	0.59	0.39
query32	3.23	0.56	0.46
query33	3.06	3.09	3.10
query34	15.83	5.18	4.52
query35	4.57	4.52	4.56
query36	0.69	0.50	0.49
query37	0.09	0.06	0.07
query38	0.05	0.04	0.04
query39	0.04	0.03	0.03
query40	0.17	0.13	0.12
query41	0.08	0.02	0.02
query42	0.03	0.02	0.02
query43	0.04	0.03	0.02
Total cold run time: 105.35 s
Total hot run time: 30.87 s

@feiniaofeiafei feiniaofeiafei force-pushed the fix_eliminate_group_by_constant2 branch 2 times, most recently from 1d88f96 to 343dc80 Compare March 28, 2025 10:09
@feiniaofeiafei
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	25676	5034	4997	4997
q2	2049	283	159	159
q3	10425	1240	716	716
q4	10520	1014	536	536
q5	7573	2340	2309	2309
q6	183	159	131	131
q7	897	741	605	605
q8	9307	1280	1090	1090
q9	6804	5105	5105	5105
q10	6791	2302	1911	1911
q11	469	270	252	252
q12	353	354	225	225
q13	17743	3649	3072	3072
q14	223	233	206	206
q15	526	494	500	494
q16	618	624	598	598
q17	587	850	348	348
q18	7490	7196	7136	7136
q19	1249	950	586	586
q20	347	332	205	205
q21	4425	3356	2443	2443
q22	1054	1016	959	959
Total cold run time: 115309 ms
Total hot run time: 34083 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5200	5116	5131	5116
q2	241	317	228	228
q3	2141	2646	2297	2297
q4	1426	1791	1385	1385
q5	4557	4382	4339	4339
q6	214	172	132	132
q7	1963	1923	1794	1794
q8	2584	2518	2485	2485
q9	7255	7143	6964	6964
q10	2991	3205	2732	2732
q11	579	510	504	504
q12	681	768	625	625
q13	3510	3933	3302	3302
q14	295	300	279	279
q15	535	470	485	470
q16	644	673	644	644
q17	1156	1534	1429	1429
q18	7738	7566	7425	7425
q19	847	831	919	831
q20	1993	2003	1832	1832
q21	5226	4776	4763	4763
q22	1090	1039	1008	1008
Total cold run time: 52866 ms
Total hot run time: 50584 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 192881 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 343dc803b5b033750e252e1c539116c718aac5f2, data reload: false

query1	1390	1053	1053	1053
query2	6280	1927	1944	1927
query3	10985	4622	4528	4528
query4	53210	24124	23318	23318
query5	5108	626	476	476
query6	347	210	201	201
query7	4862	513	275	275
query8	298	257	232	232
query9	5457	2513	2532	2513
query10	426	323	262	262
query11	15189	15089	14757	14757
query12	156	110	107	107
query13	1041	510	393	393
query14	10325	6375	6446	6375
query15	199	204	170	170
query16	7116	669	482	482
query17	1053	758	566	566
query18	1534	411	312	312
query19	192	196	157	157
query20	119	129	118	118
query21	206	122	103	103
query22	4367	4372	4429	4372
query23	33820	33374	33279	33279
query24	6300	2460	2438	2438
query25	457	469	383	383
query26	670	266	144	144
query27	2280	494	336	336
query28	3175	2457	2422	2422
query29	584	569	454	454
query30	288	225	196	196
query31	887	855	792	792
query32	74	58	69	58
query33	435	363	321	321
query34	764	865	520	520
query35	786	817	777	777
query36	942	995	905	905
query37	120	99	74	74
query38	4208	4116	4303	4116
query39	1488	1463	1431	1431
query40	208	121	106	106
query41	56	53	50	50
query42	122	105	110	105
query43	504	494	474	474
query44	1314	827	810	810
query45	180	174	165	165
query46	849	1056	677	677
query47	1907	1909	1826	1826
query48	376	433	327	327
query49	723	520	440	440
query50	706	759	424	424
query51	4250	4320	4234	4234
query52	112	114	101	101
query53	232	263	189	189
query54	495	498	429	429
query55	80	80	82	80
query56	283	287	268	268
query57	1166	1211	1126	1126
query58	263	253	252	252
query59	2681	2843	2744	2744
query60	323	303	278	278
query61	157	159	155	155
query62	727	774	706	706
query63	223	187	193	187
query64	1607	1070	697	697
query65	4422	4320	4341	4320
query66	719	391	286	286
query67	15915	15561	15425	15425
query68	7154	883	520	520
query69	534	301	272	272
query70	1183	1107	1062	1062
query71	526	304	275	275
query72	5784	4768	4789	4768
query73	1423	643	353	353
query74	8953	9266	8863	8863
query75	4075	3238	2721	2721
query76	4212	1183	750	750
query77	685	364	355	355
query78	9839	9999	9288	9288
query79	2462	808	583	583
query80	640	506	436	436
query81	467	254	218	218
query82	438	126	96	96
query83	256	181	157	157
query84	286	94	75	75
query85	802	361	306	306
query86	357	303	294	294
query87	4426	4518	4385	4385
query88	3443	2279	2229	2229
query89	409	317	271	271
query90	1942	203	208	203
query91	154	139	111	111
query92	73	61	56	56
query93	1330	1068	597	597
query94	669	402	308	308
query95	344	277	276	276
query96	497	552	273	273
query97	3204	3232	3091	3091
query98	234	206	205	205
query99	1434	1397	1260	1260
Total cold run time: 295973 ms
Total hot run time: 192881 ms

@doris-robot
Copy link

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

query1	0.04	0.04	0.03
query2	0.13	0.10	0.11
query3	0.25	0.20	0.20
query4	1.59	0.19	0.11
query5	0.54	0.55	0.55
query6	1.20	0.71	0.71
query7	0.03	0.01	0.02
query8	0.04	0.04	0.04
query9	0.57	0.51	0.51
query10	0.61	0.59	0.57
query11	0.15	0.10	0.11
query12	0.14	0.11	0.11
query13	0.61	0.61	0.59
query14	2.80	2.68	2.78
query15	0.92	0.83	0.85
query16	0.38	0.39	0.37
query17	0.99	1.02	1.03
query18	0.22	0.20	0.19
query19	2.04	1.85	1.85
query20	0.01	0.02	0.01
query21	15.38	0.94	0.55
query22	0.76	1.14	0.71
query23	14.90	1.39	0.64
query24	6.83	1.54	1.28
query25	0.49	0.23	0.08
query26	0.61	0.16	0.14
query27	0.05	0.05	0.05
query28	9.49	0.87	0.44
query29	12.58	4.00	3.27
query30	0.26	0.09	0.06
query31	2.80	0.60	0.39
query32	3.23	0.54	0.46
query33	3.00	3.06	3.11
query34	15.82	5.13	4.49
query35	4.48	4.47	4.49
query36	0.66	0.50	0.48
query37	0.09	0.06	0.06
query38	0.04	0.04	0.04
query39	0.04	0.02	0.02
query40	0.17	0.15	0.13
query41	0.09	0.03	0.03
query42	0.04	0.02	0.02
query43	0.04	0.03	0.02
Total cold run time: 105.11 s
Total hot run time: 31.47 s

@feiniaofeiafei feiniaofeiafei marked this pull request as ready for review March 31, 2025 04:12
@feiniaofeiafei
Copy link
Contributor Author

run feut

1 similar comment
@feiniaofeiafei
Copy link
Contributor Author

run feut

@feiniaofeiafei feiniaofeiafei force-pushed the fix_eliminate_group_by_constant2 branch 2 times, most recently from fa466d1 to 3073601 Compare April 1, 2025 04:09
@feiniaofeiafei
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	26257	5088	4989	4989
q2	2092	276	197	197
q3	10400	1267	724	724
q4	10225	1023	554	554
q5	7525	2328	2421	2328
q6	198	172	134	134
q7	935	769	630	630
q8	9301	1366	1191	1191
q9	6798	5269	5177	5177
q10	6817	2320	1931	1931
q11	492	295	277	277
q12	346	367	225	225
q13	17785	3680	3094	3094
q14	224	236	214	214
q15	551	499	508	499
q16	618	629	568	568
q17	605	914	393	393
q18	7628	7300	7197	7197
q19	1211	973	565	565
q20	340	343	240	240
q21	4070	3384	3237	3237
q22	1091	1017	984	984
Total cold run time: 115509 ms
Total hot run time: 35348 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5194	5088	5139	5088
q2	256	341	240	240
q3	2204	2644	2343	2343
q4	1431	1947	1518	1518
q5	4589	4461	4443	4443
q6	212	169	129	129
q7	2001	1924	1795	1795
q8	2755	2798	2673	2673
q9	7169	7123	7095	7095
q10	3024	3177	2828	2828
q11	602	513	489	489
q12	726	803	634	634
q13	3515	3924	3306	3306
q14	284	282	264	264
q15	537	502	486	486
q16	667	691	643	643
q17	1206	1712	1419	1419
q18	7828	7610	7263	7263
q19	824	851	859	851
q20	2034	1992	1885	1885
q21	5269	4768	4638	4638
q22	1127	1043	987	987
Total cold run time: 53454 ms
Total hot run time: 51017 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 186085 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 3073601fe68e83019a95ddbc23861a899e05ca6a, data reload: false

query1	1001	500	490	490
query2	6536	1889	1873	1873
query3	6743	224	222	222
query4	26565	23240	23067	23067
query5	4316	624	457	457
query6	306	206	190	190
query7	4616	497	280	280
query8	282	233	229	229
query9	8649	2545	2556	2545
query10	436	311	241	241
query11	15461	15239	14826	14826
query12	164	118	111	111
query13	1658	527	412	412
query14	9174	6164	6183	6164
query15	214	183	170	170
query16	7290	652	484	484
query17	1199	739	594	594
query18	2001	410	325	325
query19	199	185	178	178
query20	121	118	122	118
query21	207	126	107	107
query22	4345	4305	4142	4142
query23	34040	32772	33191	32772
query24	7735	2386	2395	2386
query25	593	456	379	379
query26	1235	269	148	148
query27	2661	489	324	324
query28	4377	2402	2414	2402
query29	758	555	421	421
query30	288	217	191	191
query31	950	828	776	776
query32	79	68	67	67
query33	574	419	312	312
query34	798	856	512	512
query35	798	824	725	725
query36	931	970	885	885
query37	118	100	75	75
query38	4153	4112	4023	4023
query39	1445	1382	1393	1382
query40	210	117	103	103
query41	55	50	52	50
query42	117	102	103	102
query43	489	502	482	482
query44	1292	812	802	802
query45	175	174	162	162
query46	876	991	614	614
query47	1742	1798	1702	1702
query48	375	427	298	298
query49	789	525	432	432
query50	631	690	396	396
query51	4137	4157	4145	4145
query52	111	105	105	105
query53	231	247	183	183
query54	601	568	514	514
query55	87	84	85	84
query56	301	293	274	274
query57	1148	1148	1067	1067
query58	264	280	253	253
query59	2564	2801	2579	2579
query60	329	323	292	292
query61	135	139	131	131
query62	785	747	663	663
query63	221	184	185	184
query64	4287	1029	694	694
query65	4303	4240	4302	4240
query66	1142	423	313	313
query67	15766	15484	15373	15373
query68	8190	888	518	518
query69	467	303	265	265
query70	1233	1113	1131	1113
query71	486	329	283	283
query72	5548	4791	4724	4724
query73	712	590	340	340
query74	9432	8829	8932	8829
query75	4035	3236	2712	2712
query76	3739	1177	741	741
query77	810	457	293	293
query78	9863	10196	9308	9308
query79	2397	818	566	566
query80	623	515	437	437
query81	474	259	233	233
query82	439	124	95	95
query83	291	251	238	238
query84	292	108	87	87
query85	800	355	312	312
query86	332	313	318	313
query87	4449	4692	4440	4440
query88	3358	2200	2183	2183
query89	383	314	287	287
query90	1924	214	213	213
query91	144	138	113	113
query92	74	60	58	58
query93	1377	960	591	591
query94	667	408	320	320
query95	376	291	285	285
query96	482	547	273	273
query97	3163	3211	3201	3201
query98	230	202	210	202
query99	1457	1415	1270	1270
Total cold run time: 274426 ms
Total hot run time: 186085 ms

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

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

@morrySnow morrySnow merged commit 0f506f3 into apache:master Apr 15, 2025
30 of 31 checks passed
github-actions bot pushed a commit that referenced this pull request Apr 15, 2025
…9589)

### What problem does this PR solve?

Related PR: #32878 #49473

Problem Summary:

 SELECT
    IF(
        t.`gender` IN ('女'),
        (
            TIMESTAMPDIFF(
                YEAR,
                NOW(),
                NOW()
            )
        ),
        1
    ) AS x0,
    TIMESTAMPDIFF(
        YEAR,
        NOW(),
        NOW()
    ) AS x1
FROM
t1 AS t
GROUP BY
    x0,
    x1;

after EliminateGroupByConstant, this sql will be rewritten to

 SELECT
    IF(
        t.`gender` IN ('女'),
        0,
        1
    ) AS x0,
    0 AS x1
FROM
t1 AS t
GROUP BY
     IF(
        t.`gender` IN ('女'),
        (
            TIMESTAMPDIFF(
                YEAR,
                NOW(),
                NOW()
            )
        ),
        1
    ) ;

The select expression and the group by expression is different, and will
report error in normalizeagg.

The fix in PR #49473 may introduce another issue. Consider the following
query:

SELECT func2(100) FROM t GROUP BY func1(), func2(func1());

If func1() can be constant-folded to 100, then func2(func1()) will be
replaced with func2(100), allowing the query to execute successfully.
However, when func1() cannot be folded to 100, the query will fail. This
creates an inconsistent behavior where query execution depends on
whether func1() can be constant-folded or not, which is not an ideal
implementation.

To address this issue, this PR modifies the normalizeAgg logic to
eliminate constant group by keys. With this change, the query will
consistently fail regardless of whether func1() can be folded or not,
ensuring more predictable behavior.
seawinde pushed a commit to seawinde/doris that referenced this pull request Apr 17, 2025
…ache#49589)

### What problem does this PR solve?

Related PR: apache#32878 apache#49473

Problem Summary:

 SELECT
    IF(
        t.`gender` IN ('女'),
        (
            TIMESTAMPDIFF(
                YEAR,
                NOW(),
                NOW()
            )
        ),
        1
    ) AS x0,
    TIMESTAMPDIFF(
        YEAR,
        NOW(),
        NOW()
    ) AS x1
FROM
t1 AS t
GROUP BY
    x0,
    x1;

after EliminateGroupByConstant, this sql will be rewritten to

 SELECT
    IF(
        t.`gender` IN ('女'),
        0,
        1
    ) AS x0,
    0 AS x1
FROM
t1 AS t
GROUP BY
     IF(
        t.`gender` IN ('女'),
        (
            TIMESTAMPDIFF(
                YEAR,
                NOW(),
                NOW()
            )
        ),
        1
    ) ;

The select expression and the group by expression is different, and will
report error in normalizeagg.

The fix in PR apache#49473 may introduce another issue. Consider the following
query:

SELECT func2(100) FROM t GROUP BY func1(), func2(func1());

If func1() can be constant-folded to 100, then func2(func1()) will be
replaced with func2(100), allowing the query to execute successfully.
However, when func1() cannot be folded to 100, the query will fail. This
creates an inconsistent behavior where query execution depends on
whether func1() can be constant-folded or not, which is not an ideal
implementation.

To address this issue, this PR modifies the normalizeAgg logic to
eliminate constant group by keys. With this change, the query will
consistently fail regardless of whether func1() can be folded or not,
ensuring more predictable behavior.
feiniaofeiafei added a commit to feiniaofeiafei/doris that referenced this pull request Apr 21, 2025
…ache#49589)

Related PR: apache#32878 apache#49473

Problem Summary:

 SELECT
    IF(
        t.`gender` IN ('女'),
        (
            TIMESTAMPDIFF(
                YEAR,
                NOW(),
                NOW()
            )
        ),
        1
    ) AS x0,
    TIMESTAMPDIFF(
        YEAR,
        NOW(),
        NOW()
    ) AS x1
FROM
t1 AS t
GROUP BY
    x0,
    x1;

after EliminateGroupByConstant, this sql will be rewritten to

 SELECT
    IF(
        t.`gender` IN ('女'),
        0,
        1
    ) AS x0,
    0 AS x1
FROM
t1 AS t
GROUP BY
     IF(
        t.`gender` IN ('女'),
        (
            TIMESTAMPDIFF(
                YEAR,
                NOW(),
                NOW()
            )
        ),
        1
    ) ;

The select expression and the group by expression is different, and will
report error in normalizeagg.

The fix in PR apache#49473 may introduce another issue. Consider the following
query:

SELECT func2(100) FROM t GROUP BY func1(), func2(func1());

If func1() can be constant-folded to 100, then func2(func1()) will be
replaced with func2(100), allowing the query to execute successfully.
However, when func1() cannot be folded to 100, the query will fail. This
creates an inconsistent behavior where query execution depends on
whether func1() can be constant-folded or not, which is not an ideal
implementation.

To address this issue, this PR modifies the normalizeAgg logic to
eliminate constant group by keys. With this change, the query will
consistently fail regardless of whether func1() can be folded or not,
ensuring more predictable behavior.
dataroaring pushed a commit that referenced this pull request May 7, 2025
feiniaofeiafei added a commit to feiniaofeiafei/doris that referenced this pull request May 8, 2025
…ache#49589)

Related PR: apache#32878 apache#49473

Problem Summary:

 SELECT
    IF(
        t.`gender` IN ('女'),
        (
            TIMESTAMPDIFF(
                YEAR,
                NOW(),
                NOW()
            )
        ),
        1
    ) AS x0,
    TIMESTAMPDIFF(
        YEAR,
        NOW(),
        NOW()
    ) AS x1
FROM
t1 AS t
GROUP BY
    x0,
    x1;

after EliminateGroupByConstant, this sql will be rewritten to

 SELECT
    IF(
        t.`gender` IN ('女'),
        0,
        1
    ) AS x0,
    0 AS x1
FROM
t1 AS t
GROUP BY
     IF(
        t.`gender` IN ('女'),
        (
            TIMESTAMPDIFF(
                YEAR,
                NOW(),
                NOW()
            )
        ),
        1
    ) ;

The select expression and the group by expression is different, and will
report error in normalizeagg.

The fix in PR apache#49473 may introduce another issue. Consider the following
query:

SELECT func2(100) FROM t GROUP BY func1(), func2(func1());

If func1() can be constant-folded to 100, then func2(func1()) will be
replaced with func2(100), allowing the query to execute successfully.
However, when func1() cannot be folded to 100, the query will fail. This
creates an inconsistent behavior where query execution depends on
whether func1() can be constant-folded or not, which is not an ideal
implementation.

To address this issue, this PR modifies the normalizeAgg logic to
eliminate constant group by keys. With this change, the query will
consistently fail regardless of whether func1() can be folded or not,
ensuring more predictable behavior.
yiguolei pushed a commit that referenced this pull request May 8, 2025
@yiguolei yiguolei mentioned this pull request May 13, 2025
koarz pushed a commit to koarz/doris that referenced this pull request Jun 4, 2025
…ache#49589)

### What problem does this PR solve?

Related PR: apache#32878 apache#49473

Problem Summary:

 SELECT
    IF(
        t.`gender` IN ('女'),
        (
            TIMESTAMPDIFF(
                YEAR,
                NOW(),
                NOW()
            )
        ),
        1
    ) AS x0,
    TIMESTAMPDIFF(
        YEAR,
        NOW(),
        NOW()
    ) AS x1
FROM
t1 AS t
GROUP BY
    x0,
    x1;

after EliminateGroupByConstant, this sql will be rewritten to

 SELECT
    IF(
        t.`gender` IN ('女'),
        0,
        1
    ) AS x0,
    0 AS x1
FROM
t1 AS t
GROUP BY
     IF(
        t.`gender` IN ('女'),
        (
            TIMESTAMPDIFF(
                YEAR,
                NOW(),
                NOW()
            )
        ),
        1
    ) ;

The select expression and the group by expression is different, and will
report error in normalizeagg.

The fix in PR apache#49473 may introduce another issue. Consider the following
query:

SELECT func2(100) FROM t GROUP BY func1(), func2(func1());

If func1() can be constant-folded to 100, then func2(func1()) will be
replaced with func2(100), allowing the query to execute successfully.
However, when func1() cannot be folded to 100, the query will fail. This
creates an inconsistent behavior where query execution depends on
whether func1() can be constant-folded or not, which is not an ideal
implementation.

To address this issue, this PR modifies the normalizeAgg logic to
eliminate constant group by keys. With this change, the query will
consistently fail regardless of whether func1() can be folded or not,
ensuring more predictable behavior.
morrySnow pushed a commit that referenced this pull request Jul 4, 2025
koarz pushed a commit to koarz/doris that referenced this pull request Jul 4, 2025
koarz pushed a commit to koarz/doris that referenced this pull request Jul 4, 2025
seawinde pushed a commit to seawinde/doris that referenced this pull request Jul 4, 2025
GoGoWen pushed a commit to GoGoWen/incubator-doris that referenced this pull request Sep 26, 2025
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. dev/2.1.10-merged dev/3.0.6-merged reviewed usercase Important user case type label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants