MDEV-23687 Assertion `is_valid_value_slow()' failed in Datetime::Datetime upon EXTRACT under mode ZERO_DATE_TIME_CAST

Item_{date|datetime}_typecase::get_date() erroneously passed the
TIME_INTERVAL_DAY flag from the caller to args[0] which made
CAST('100000:00:00' AS DATETIME) parse '100000:00:00' as TIME
rather that DATETIME.
Suppressing this flag.
This commit is contained in:
Alexander Barkov 2024-11-22 12:11:32 +04:00
parent cf2d49ddcf
commit 39f1f30f68
3 changed files with 39 additions and 2 deletions

View file

@ -1478,5 +1478,30 @@ NULL
Warnings:
Warning 1292 Incorrect interval value: '42949672955000x1'
#
# MDEV-23687 Assertion `is_valid_value_slow()' failed in Datetime::Datetime upon EXTRACT under mode ZERO_DATE_TIME_CAST
#
SET SESSION old_mode='ZERO_DATE_TIME_CAST';
SELECT CAST('100000:00:00' AS DATETIME);
CAST('100000:00:00' AS DATETIME)
NULL
Warnings:
Warning 1292 Incorrect datetime value: '100000:00:00'
SELECT EXTRACT(DAY FROM CAST('100000:00:00' AS DATETIME));
EXTRACT(DAY FROM CAST('100000:00:00' AS DATETIME))
NULL
Warnings:
Warning 1292 Incorrect datetime value: '100000:00:00'
SELECT CAST('100000:00:00' AS DATE);
CAST('100000:00:00' AS DATE)
NULL
Warnings:
Warning 1292 Incorrect datetime value: '100000:00:00'
SELECT EXTRACT(DAY FROM CAST('100000:00:00' AS DATE));
EXTRACT(DAY FROM CAST('100000:00:00' AS DATE))
NULL
Warnings:
Warning 1292 Incorrect datetime value: '100000:00:00'
SET SESSION old_mode=DEFAULT;
#
# End of 10.5 tests
#

View file

@ -517,6 +517,16 @@ DROP FUNCTION select02;
SELECT EXTRACT(HOUR_MICROSECOND FROM '42949672955000x1');
--echo #
--echo # MDEV-23687 Assertion `is_valid_value_slow()' failed in Datetime::Datetime upon EXTRACT under mode ZERO_DATE_TIME_CAST
--echo #
SET SESSION old_mode='ZERO_DATE_TIME_CAST';
SELECT CAST('100000:00:00' AS DATETIME);
SELECT EXTRACT(DAY FROM CAST('100000:00:00' AS DATETIME));
SELECT CAST('100000:00:00' AS DATE);
SELECT EXTRACT(DAY FROM CAST('100000:00:00' AS DATE));
SET SESSION old_mode=DEFAULT;
--echo #
--echo # End of 10.5 tests

View file

@ -2585,7 +2585,8 @@ Sql_mode_dependency Item_time_typecast::value_depends_on_sql_mode() const
bool Item_date_typecast::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate)
{
date_mode_t tmp= (fuzzydate | sql_mode_for_dates(thd)) & ~TIME_TIME_ONLY;
date_mode_t tmp= (fuzzydate | sql_mode_for_dates(thd))
& ~TIME_TIME_ONLY & ~TIME_INTERVAL_DAY;
// Force truncation
Date *d= new(ltime) Date(thd, args[0], Date::Options(date_conv_mode_t(tmp)));
return (null_value= !d->is_valid_date());
@ -2594,7 +2595,8 @@ bool Item_date_typecast::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzy
bool Item_datetime_typecast::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate)
{
date_mode_t tmp= (fuzzydate | sql_mode_for_dates(thd)) & ~TIME_TIME_ONLY;
date_mode_t tmp= (fuzzydate | sql_mode_for_dates(thd))
& ~TIME_TIME_ONLY & ~TIME_INTERVAL_DAY;
// Force rounding if the current sql_mode says so
Datetime::Options opt(date_conv_mode_t(tmp), thd);
Datetime *dt= new(ltime) Datetime(thd, args[0], opt,