Skip to content

Conversation

@Yulei-Yang
Copy link
Contributor

@Yulei-Yang Yulei-Yang commented Jun 20, 2024

How to Reproduce:
Issue1: use datetimev1 and datev2 as parameters in function coalesce

admin set frontend config ("enable_date_conversion"="false");
admin set frontend config ("disable_datev1"="false");
drop table test_cls;
CREATE TABLE `test_cls` (
    `id` int(11) NOT NULL COMMENT '',
    `name` varchar(32) NOT NULL COMMENT '',
    `dt` datetime NOT NULL
) ENGINE=OLAP
UNIQUE KEY(`id`)
DISTRIBUTED BY HASH(`id`) BUCKETS 2
PROPERTIES(
    "replication_allocation" = "tag.location.default: 1"
);

sql SET enable_nereids_planner=false; select dt from test_cls where coalesce (dt, str_to_date(concat('202306', '01'), '%Y%m%d')) >= '2023-06-01'; return no data, which is wrong

when see the excution plan
SET enable_nereids_planner=false; explain select dt from test_cls where coalesce (dt, str_to_date(concat('202306', '01'), '%Y%m%d')) >= '2023-06-01';

you can see error predicate:
CAST(coalesce(CAST(dt AS BIGINT), 20230601) AS DOUBLE) >= NULL

after fix:
CAST(coalesce(dt, '2023-06-01') AS DATETIMEV2(0)) >= '2023-06-01 00:00:00'

Issue2: use datetimev2 and datev2 as parameters in function coalesce

admin set frontend config ("enable_date_conversion"="true");
admin set frontend config ("disable_datev1"="true");
drop table test_cls;
CREATE TABLE `test_cls` (
    `id` int(11) NOT NULL COMMENT '',
    `name` varchar(32) NOT NULL COMMENT '',
    `dt` datetime NOT NULL
) ENGINE=OLAP
UNIQUE KEY(`id`)
DISTRIBUTED BY HASH(`id`) BUCKETS 2
PROPERTIES(
    "replication_allocation" = "tag.location.default: 1"
);

sql SET enable_nereids_planner=false; select dt from test_cls where coalesce (dt, str_to_date(concat('202306', '01'), '%Y%m%d')) >= '2023-06-01'; return no data, which is wrong

when see the excution plan
SET enable_nereids_planner=false; explain select dt from test_cls where coalesce (dt, str_to_date(concat('202306', '01'), '%Y%m%d')) >= '2023-06-01';

you can see error predicate:
CAST(coalesce(CAST(dt AS BIGINT), 20230601) AS DOUBLE) >= NULL

after fix:
coalesce(dt, '2023-06-01') >= '2023-06-01 00:00:00'

@doris-robot
Copy link

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR

Since 2024-03-18, the Document has been moved to doris-website.
See Doris Document.

@Yulei-Yang
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17728	4459	4338	4338
q2	2066	157	147	147
q3	10276	1916	1936	1916
q4	10102	1242	1356	1242
q5	8497	3978	3969	3969
q6	235	149	127	127
q7	2032	1588	1623	1588
q8	9375	2758	2723	2723
q9	11027	10308	10325	10308
q10	8662	3513	3527	3513
q11	413	245	253	245
q12	473	299	304	299
q13	18342	3953	4060	3953
q14	357	337	331	331
q15	521	458	460	458
q16	685	566	557	557
q17	1143	994	980	980
q18	7398	6898	6917	6898
q19	1814	1651	1640	1640
q20	554	315	308	308
q21	4465	4157	4054	4054
q22	541	460	452	452
Total cold run time: 116706 ms
Total hot run time: 50046 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4320	4326	4327	4326
q2	321	230	226	226
q3	4146	4126	4148	4126
q4	2757	2736	2758	2736
q5	7129	7125	7076	7076
q6	237	122	120	120
q7	3280	2875	2796	2796
q8	4371	4474	4512	4474
q9	17064	16790	16819	16790
q10	4218	4247	4259	4247
q11	758	699	676	676
q12	1021	851	876	851
q13	6482	3762	3744	3744
q14	459	425	422	422
q15	520	467	457	457
q16	744	681	669	669
q17	3758	3863	3795	3795
q18	8965	8816	8816	8816
q19	1737	1740	1656	1656
q20	2373	2134	2130	2130
q21	8558	8407	8467	8407
q22	1075	946	974	946
Total cold run time: 84293 ms
Total hot run time: 79486 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 202968 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 765b848a82659e656668d17628f5755985e612fd, data reload: false

query1	938	430	389	389
query2	6538	2798	2628	2628
query3	6922	201	204	201
query4	20879	17917	17888	17888
query5	19726	6542	6442	6442
query6	299	218	234	218
query7	4154	296	307	296
query8	420	480	418	418
query9	3151	2700	2666	2666
query10	419	335	290	290
query11	11362	10796	10686	10686
query12	125	78	79	78
query13	5591	689	671	671
query14	17812	13290	13492	13290
query15	357	253	247	247
query16	6470	290	270	270
query17	1693	1451	872	872
query18	2305	412	424	412
query19	202	145	148	145
query20	81	78	82	78
query21	196	98	99	98
query22	5296	4951	5101	4951
query23	32531	31867	31701	31701
query24	6920	6539	6551	6539
query25	526	428	429	428
query26	532	159	167	159
query27	1827	291	294	291
query28	6222	2407	2372	2372
query29	2999	2841	2766	2766
query30	242	167	170	167
query31	927	757	750	750
query32	70	66	52	52
query33	414	263	255	255
query34	844	471	487	471
query35	1112	931	916	916
query36	1283	1127	1207	1127
query37	92	66	59	59
query38	3069	2927	2916	2916
query39	1386	1305	1329	1305
query40	208	99	95	95
query41	49	44	44	44
query42	85	80	83	80
query43	694	720	719	719
query44	1129	712	719	712
query45	258	241	238	238
query46	1249	964	1006	964
query47	1868	1768	1788	1768
query48	1030	701	698	698
query49	619	374	373	373
query50	855	604	608	604
query51	4834	4625	4671	4625
query52	100	91	97	91
query53	447	317	321	317
query54	2674	2467	2476	2467
query55	94	72	87	72
query56	247	225	207	207
query57	1264	1130	1179	1130
query58	214	213	215	213
query59	4115	4172	3909	3909
query60	219	200	207	200
query61	96	94	95	94
query62	841	451	488	451
query63	492	351	347	347
query64	2367	1499	1476	1476
query65	3634	3600	3570	3570
query66	770	384	379	379
query67	16278	14996	18089	14996
query68	8661	652	635	635
query69	593	350	344	344
query70	1517	1410	1332	1332
query71	411	298	314	298
query72	6499	3467	3479	3467
query73	734	320	313	313
query74	6256	5976	5837	5837
query75	5180	3714	3659	3659
query76	5164	1144	1187	1144
query77	843	258	257	257
query78	12556	11609	11847	11609
query79	8567	638	657	638
query80	1722	394	410	394
query81	511	239	229	229
query82	1687	98	93	93
query83	172	136	133	133
query84	261	73	71	71
query85	879	322	319	319
query86	335	310	292	292
query87	3246	3086	3024	3024
query88	5117	2356	2332	2332
query89	393	291	283	283
query90	1930	207	208	207
query91	172	142	145	142
query92	60	51	53	51
query93	5952	545	578	545
query94	717	215	217	215
query95	1126	1063	1060	1060
query96	652	327	327	327
query97	6482	6363	6395	6363
query98	194	190	166	166
query99	2959	842	910	842
Total cold run time: 314210 ms
Total hot run time: 202968 ms

@doris-robot
Copy link

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

query1	0.02	0.03	0.03
query2	0.07	0.03	0.02
query3	0.25	0.05	0.05
query4	1.80	0.07	0.08
query5	0.54	0.52	0.51
query6	1.23	0.61	0.62
query7	0.02	0.01	0.01
query8	0.03	0.02	0.02
query9	0.53	0.49	0.47
query10	0.54	0.52	0.53
query11	0.12	0.09	0.09
query12	0.11	0.09	0.09
query13	0.61	0.62	0.61
query14	0.78	0.79	0.81
query15	0.77	0.76	0.77
query16	0.36	0.38	0.36
query17	1.02	1.01	1.03
query18	0.23	0.26	0.25
query19	1.91	1.87	1.87
query20	0.02	0.01	0.01
query21	15.46	0.57	0.54
query22	1.93	2.15	1.57
query23	17.05	1.01	1.07
query24	5.66	0.76	1.38
query25	0.36	0.14	0.05
query26	0.63	0.16	0.15
query27	0.05	0.04	0.03
query28	7.45	0.72	0.78
query29	12.63	2.37	2.37
query30	0.62	0.49	0.53
query31	2.81	0.38	0.37
query32	3.37	0.50	0.50
query33	3.05	3.08	3.06
query34	15.24	4.81	4.80
query35	4.88	4.83	4.83
query36	1.06	1.01	1.02
query37	0.05	0.04	0.05
query38	0.03	0.02	0.02
query39	0.02	0.02	0.01
query40	0.16	0.14	0.14
query41	0.07	0.02	0.01
query42	0.02	0.01	0.01
query43	0.02	0.01	0.02
Total cold run time: 103.58 s
Total hot run time: 30.65 s

@doris-robot
Copy link

Load test result on machine: 'aliyun_ecs.c7a.8xlarge_32C64G'

Load test result on commit 765b848a82659e656668d17628f5755985e612fd with default session variables
Stream load json:         21 seconds loaded 2358488459 Bytes, about 107 MB/s
Stream load orc:          58 seconds loaded 1101869774 Bytes, about 18 MB/s
Stream load parquet:      31 seconds loaded 861443392 Bytes, about 26 MB/s
Insert into select:       21.2 seconds inserted 10000000 Rows, about 471K ops/s

@Yulei-Yang Yulei-Yang changed the title [fix](coalesce) fix no data issue when use datetimev1/datatimev2 & datev2 as parameter in legacy planner [fix](planner) fix no data issue when use datetimev1/datatimev2 & datev2 as parameter in legacy planner Jun 20, 2024
@Yulei-Yang
Copy link
Contributor Author

run p0

@Yulei-Yang
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

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

------ Round 1 ----------------------------------
q1	17923	4371	4315	4315
q2	2099	152	161	152
q3	10517	1881	1908	1881
q4	10347	1241	1314	1241
q5	8369	3859	3893	3859
q6	237	150	126	126
q7	2033	1618	1624	1618
q8	9299	2732	2709	2709
q9	10609	10335	10151	10151
q10	8623	3525	3462	3462
q11	413	245	253	245
q12	480	311	310	310
q13	18359	3943	4034	3943
q14	356	320	318	318
q15	503	463	464	463
q16	693	565	571	565
q17	1132	976	977	976
q18	7230	6934	6936	6934
q19	1827	1684	1647	1647
q20	524	295	297	295
q21	4419	4125	4070	4070
q22	540	453	446	446
Total cold run time: 116532 ms
Total hot run time: 49726 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4366	4311	4308	4308
q2	321	222	225	222
q3	4212	4158	4203	4158
q4	2788	2793	2775	2775
q5	7283	7113	7076	7076
q6	234	120	117	117
q7	3242	2838	2807	2807
q8	4358	4466	4484	4466
q9	16930	16739	16780	16739
q10	4224	4267	4294	4267
q11	764	680	699	680
q12	1041	861	834	834
q13	6571	3741	3741	3741
q14	457	435	435	435
q15	509	462	447	447
q16	745	670	683	670
q17	3784	3794	3850	3794
q18	8717	8717	8776	8717
q19	1735	1708	1701	1701
q20	2353	2106	2097	2097
q21	8577	8497	8531	8497
q22	1061	948	993	948
Total cold run time: 84272 ms
Total hot run time: 79496 ms

@github-actions
Copy link
Contributor

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

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Jun 20, 2024
@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

@Yulei-Yang Yulei-Yang changed the title [fix](planner) fix no data issue when use datetimev1/datatimev2 & datev2 as parameter in legacy planner [fix](planner) fix no data issue when use datetimev1/datatimev2 & datev2 as function coalesce's parameter in legacy planner Jun 20, 2024
@doris-robot
Copy link

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

query1	958	424	380	380
query2	6530	2924	2673	2673
query3	6922	210	200	200
query4	20512	17959	18026	17959
query5	19739	6500	6458	6458
query6	278	213	237	213
query7	4180	298	309	298
query8	435	401	433	401
query9	3153	2734	2679	2679
query10	406	302	287	287
query11	11387	10632	10754	10632
query12	124	78	76	76
query13	5601	688	693	688
query14	17801	13572	13388	13388
query15	363	243	240	240
query16	6475	289	264	264
query17	1709	1451	875	875
query18	2313	415	400	400
query19	204	149	152	149
query20	78	78	81	78
query21	198	98	97	97
query22	5182	5105	4970	4970
query23	32289	31666	32005	31666
query24	6959	6466	6478	6466
query25	522	428	440	428
query26	527	159	161	159
query27	1910	297	302	297
query28	6181	2375	2335	2335
query29	2911	2792	2561	2561
query30	245	167	165	165
query31	932	755	735	735
query32	75	62	62	62
query33	402	247	249	247
query34	851	464	471	464
query35	1103	939	912	912
query36	1386	1168	1055	1055
query37	94	60	62	60
query38	3098	2960	2963	2960
query39	1371	1314	1321	1314
query40	207	97	97	97
query41	45	43	44	43
query42	86	79	86	79
query43	772	710	701	701
query44	1187	729	720	720
query45	249	239	234	234
query46	1209	987	972	972
query47	1923	1687	1795	1687
query48	1027	733	704	704
query49	630	373	364	364
query50	860	618	622	618
query51	4728	4578	4646	4578
query52	88	87	85	85
query53	454	338	325	325
query54	2667	2446	2458	2446
query55	82	89	81	81
query56	245	216	209	209
query57	1221	1028	1072	1028
query58	220	214	198	198
query59	4203	3826	4042	3826
query60	227	195	193	193
query61	98	95	100	95
query62	867	483	457	457
query63	483	343	346	343
query64	2583	1452	1384	1384
query65	3618	3544	3556	3544
query66	781	384	374	374
query67	15801	15918	14964	14964
query68	9596	647	655	647
query69	566	339	342	339
query70	1656	1439	1372	1372
query71	424	309	321	309
query72	6519	3473	3450	3450
query73	743	325	324	324
query74	6344	5849	5886	5849
query75	5481	3748	3729	3729
query76	5989	1138	1209	1138
query77	1020	257	257	257
query78	12538	11844	12626	11844
query79	8575	657	643	643
query80	1173	403	415	403
query81	491	240	227	227
query82	640	102	91	91
query83	165	129	130	129
query84	265	69	70	69
query85	870	316	319	316
query86	335	291	306	291
query87	3293	3017	3000	3000
query88	4310	2337	2329	2329
query89	404	302	315	302
query90	1940	215	216	215
query91	172	141	144	141
query92	59	53	50	50
query93	4623	604	606	604
query94	683	212	212	212
query95	1108	1049	1044	1044
query96	648	344	322	322
query97	6455	6352	6248	6248
query98	190	183	181	181
query99	3010	1028	915	915
Total cold run time: 312250 ms
Total hot run time: 202630 ms

@doris-robot
Copy link

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

query1	0.02	0.03	0.02
query2	0.08	0.02	0.02
query3	0.25	0.06	0.05
query4	1.77	0.07	0.08
query5	0.54	0.52	0.51
query6	1.24	0.62	0.62
query7	0.01	0.01	0.01
query8	0.04	0.02	0.03
query9	0.53	0.48	0.48
query10	0.53	0.53	0.53
query11	0.12	0.09	0.08
query12	0.11	0.09	0.09
query13	0.63	0.62	0.61
query14	0.79	0.78	0.79
query15	0.77	0.77	0.78
query16	0.36	0.36	0.36
query17	1.02	1.03	0.98
query18	0.21	0.24	0.26
query19	1.89	1.84	1.82
query20	0.02	0.01	0.01
query21	15.46	0.55	0.55
query22	2.43	2.57	1.66
query23	17.23	1.16	1.12
query24	5.14	1.78	1.05
query25	0.41	0.06	0.04
query26	0.62	0.16	0.15
query27	0.05	0.03	0.04
query28	7.58	0.73	0.72
query29	12.65	2.24	2.34
query30	0.58	0.55	0.51
query31	2.81	0.39	0.37
query32	3.38	0.49	0.50
query33	3.06	3.05	3.10
query34	15.28	4.78	4.81
query35	4.84	4.86	4.84
query36	1.07	1.01	1.02
query37	0.06	0.04	0.04
query38	0.04	0.02	0.02
query39	0.02	0.02	0.02
query40	0.16	0.15	0.14
query41	0.07	0.01	0.01
query42	0.02	0.02	0.01
query43	0.03	0.02	0.01
Total cold run time: 103.92 s
Total hot run time: 30.93 s

@doris-robot
Copy link

Load test result on machine: 'aliyun_ecs.c7a.8xlarge_32C64G'

Load test result on commit c24b36b47a85acac90ae68861f5d1d0848eeeb65 with default session variables
Stream load json:         20 seconds loaded 2358488459 Bytes, about 112 MB/s
Stream load orc:          58 seconds loaded 1101869774 Bytes, about 18 MB/s
Stream load parquet:      32 seconds loaded 861443392 Bytes, about 25 MB/s
Insert into select:       21.2 seconds inserted 10000000 Rows, about 471K ops/s

Copy link
Contributor

@lide-reed lide-reed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lide-reed lide-reed merged commit bb9d532 into apache:branch-2.0 Jun 20, 2024
@Yulei-Yang Yulei-Yang deleted the fix_coalesce_no_result branch June 20, 2024 07:26
morrySnow pushed a commit that referenced this pull request Jun 25, 2024
…sce & ifnull (#36724)

cherry-pick from branch-2.0 #36688, #36640, #36583

How to Reproduce:
Issue1: use datetimev1 and datev2 as parameters in function coalesce

admin set frontend config ("enable_date_conversion"="false");
admin set frontend config ("disable_datev1"="false");
drop table test_cls;
CREATE TABLE `test_cls` (
    `id` int(11) NOT NULL COMMENT '',
    `name` varchar(32) NOT NULL COMMENT '',
    `dt` datetime NOT NULL
) ENGINE=OLAP
UNIQUE KEY(`id`)
DISTRIBUTED BY HASH(`id`) BUCKETS 2
PROPERTIES(
    "replication_allocation" = "tag.location.default: 1"
);

SET enable_nereids_planner=false; 
select dt from test_cls where coalesce (dt, str_to_date(concat('202306', '01'), '%Y%m%d')) >= '2023-06-01';
return no data, which is wrong. 

when see the excution plan
SET enable_nereids_planner=false;
explain select dt from test_cls where coalesce (dt, str_to_date(concat('202306', '01'), '%Y%m%d')) >= '2023-06-01';

you can see error predicate:
CAST(coalesce(CAST(`dt` AS BIGINT), 20230601) AS DOUBLE) >= NULL

after fix:
CAST(coalesce(`dt`, '2023-06-01') AS DATETIMEV2(0)) >= '2023-06-01 00:00:00'


Issue2: use datetimev2 and datev2 as parameters in function coalesce

admin set frontend config ("enable_date_conversion"="true");
admin set frontend config ("disable_datev1"="true");
drop table test_cls;
CREATE TABLE `test_cls` (
    `id` int(11) NOT NULL COMMENT '',
    `name` varchar(32) NOT NULL COMMENT '',
    `dt` datetime NOT NULL
) ENGINE=OLAP
UNIQUE KEY(`id`)
DISTRIBUTED BY HASH(`id`) BUCKETS 2
PROPERTIES(
    "replication_allocation" = "tag.location.default: 1"
);

SET enable_nereids_planner=false;
select dt from test_cls where coalesce (dt, str_to_date(concat('202306', '01'), '%Y%m%d')) >= '2023-06-01';
return no data, which is wrong

when see the excution plan
SET enable_nereids_planner=false;
explain select dt from test_cls where coalesce (dt, str_to_date(concat('202306', '01'), '%Y%m%d')) >= '2023-06-01';

you can see error predicate:
CAST(coalesce(CAST(`dt` AS BIGINT), 20230601) AS DOUBLE) >= NULL

after fix:
coalesce(`dt`, '2023-06-01') >= '2023-06-01 00:00:00' 


Issue3: extend it to multiple parameters.
Steps to reproduce:

admin set frontend config ("enable_date_conversion"="false");
admin set frontend config ("disable_datev1"="false");

drop table test_cls;
CREATE TABLE `test_cls` (
    `id` int(11) NOT NULL COMMENT '',
    `name` varchar(32) NOT NULL COMMENT '',
    `dt` datetime NOT NULL
) ENGINE=OLAP
UNIQUE KEY(`id`)
DISTRIBUTED BY HASH(`id`) BUCKETS 2
PROPERTIES(
    "replication_allocation" = "tag.location.default: 1"
);
SET enable_nereids_planner=false;

error sql:
select dt from test_cls where coalesce (dt, dt, str_to_date(concat('202306', '01'), '%Y%m%d')) >= '2023-06-01';


explain it and find wrong predicate:
CAST(coalesce(CAST(`dt` AS BIGINT), CAST(`dt` AS BIGINT), 20230601) AS DOUBLE) >= NULL

after fix:
explain it 
coalesce(CAST(`dt` AS DATETIMEV2(0)), CAST(`dt` AS DATETIMEV2(0)), '2023-06-01 00:00:00') >= '2023-06-01 00:00:00'


Issue3: nereids has the same issue with legacy planner
dataroaring pushed a commit that referenced this pull request Jun 26, 2024
…sce & ifnull (#36724)

cherry-pick from branch-2.0 #36688, #36640, #36583

How to Reproduce:
Issue1: use datetimev1 and datev2 as parameters in function coalesce

admin set frontend config ("enable_date_conversion"="false");
admin set frontend config ("disable_datev1"="false");
drop table test_cls;
CREATE TABLE `test_cls` (
    `id` int(11) NOT NULL COMMENT '',
    `name` varchar(32) NOT NULL COMMENT '',
    `dt` datetime NOT NULL
) ENGINE=OLAP
UNIQUE KEY(`id`)
DISTRIBUTED BY HASH(`id`) BUCKETS 2
PROPERTIES(
    "replication_allocation" = "tag.location.default: 1"
);

SET enable_nereids_planner=false; 
select dt from test_cls where coalesce (dt, str_to_date(concat('202306', '01'), '%Y%m%d')) >= '2023-06-01';
return no data, which is wrong. 

when see the excution plan
SET enable_nereids_planner=false;
explain select dt from test_cls where coalesce (dt, str_to_date(concat('202306', '01'), '%Y%m%d')) >= '2023-06-01';

you can see error predicate:
CAST(coalesce(CAST(`dt` AS BIGINT), 20230601) AS DOUBLE) >= NULL

after fix:
CAST(coalesce(`dt`, '2023-06-01') AS DATETIMEV2(0)) >= '2023-06-01 00:00:00'


Issue2: use datetimev2 and datev2 as parameters in function coalesce

admin set frontend config ("enable_date_conversion"="true");
admin set frontend config ("disable_datev1"="true");
drop table test_cls;
CREATE TABLE `test_cls` (
    `id` int(11) NOT NULL COMMENT '',
    `name` varchar(32) NOT NULL COMMENT '',
    `dt` datetime NOT NULL
) ENGINE=OLAP
UNIQUE KEY(`id`)
DISTRIBUTED BY HASH(`id`) BUCKETS 2
PROPERTIES(
    "replication_allocation" = "tag.location.default: 1"
);

SET enable_nereids_planner=false;
select dt from test_cls where coalesce (dt, str_to_date(concat('202306', '01'), '%Y%m%d')) >= '2023-06-01';
return no data, which is wrong

when see the excution plan
SET enable_nereids_planner=false;
explain select dt from test_cls where coalesce (dt, str_to_date(concat('202306', '01'), '%Y%m%d')) >= '2023-06-01';

you can see error predicate:
CAST(coalesce(CAST(`dt` AS BIGINT), 20230601) AS DOUBLE) >= NULL

after fix:
coalesce(`dt`, '2023-06-01') >= '2023-06-01 00:00:00' 


Issue3: extend it to multiple parameters.
Steps to reproduce:

admin set frontend config ("enable_date_conversion"="false");
admin set frontend config ("disable_datev1"="false");

drop table test_cls;
CREATE TABLE `test_cls` (
    `id` int(11) NOT NULL COMMENT '',
    `name` varchar(32) NOT NULL COMMENT '',
    `dt` datetime NOT NULL
) ENGINE=OLAP
UNIQUE KEY(`id`)
DISTRIBUTED BY HASH(`id`) BUCKETS 2
PROPERTIES(
    "replication_allocation" = "tag.location.default: 1"
);
SET enable_nereids_planner=false;

error sql:
select dt from test_cls where coalesce (dt, dt, str_to_date(concat('202306', '01'), '%Y%m%d')) >= '2023-06-01';


explain it and find wrong predicate:
CAST(coalesce(CAST(`dt` AS BIGINT), CAST(`dt` AS BIGINT), 20230601) AS DOUBLE) >= NULL

after fix:
explain it 
coalesce(CAST(`dt` AS DATETIMEV2(0)), CAST(`dt` AS DATETIMEV2(0)), '2023-06-01 00:00:00') >= '2023-06-01 00:00:00'


Issue3: nereids has the same issue with legacy planner
mongo360 pushed a commit to mongo360/doris that referenced this pull request Aug 16, 2024
…ev2 as function coalesce's parameter in legacy planner (apache#36583)
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.0.12-merged kind/test reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants