MDEV-25593 Assertion `0' failed in Type_handler_temporal_result::Item_get_date on double EXECUTE

When binding to NULL, DEFAULT or IGNORE from an Item value, Item_param did not
change m_type_handler, so its value remained from the previous bind.
Thid led to DBUG_ASSERTs in Item_param::get_date() and
Timestamp_or_zero_datetime_native_null.

Fix:

Set Item_param::m_type_handler to &type_handler_null when
binding from an Item returning NULL.

This patch also fixes MDEV-35427.
This commit is contained in:
Alexander Barkov 2024-11-19 12:44:42 +04:00 committed by Oleksandr Byelkin
parent ecf2e131bd
commit 3de412fbe8
7 changed files with 143 additions and 9 deletions

View file

@ -191,3 +191,58 @@ Warnings:
Warning 1292 Truncated incorrect INTEGER value: '+ -><()~*:""&|'
SET @@sort_buffer_size=DEFAULT;
End of 5.0 tests.
# Start of 10.5 tests
#
# MDEV-25593 Assertion `0' failed in Type_handler_temporal_result::Item_get_date on double EXECUTE
#
SET time_zone='+00:00';
SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30');
PREPARE stmt FROM 'SELECT ? AS c1';
EXECUTE stmt USING current_timestamp;
c1
2001-01-01 10:20:30
EXECUTE stmt USING @unknown;
c1
NULL
DEALLOCATE PREPARE stmt;
PREPARE stmt FROM 'SELECT ? AS c1 FROM DUAL';
EXECUTE stmt USING current_time;
c1
10:20:30
EXECUTE stmt USING DEFAULT;
c1
NULL
DEALLOCATE PREPARE stmt;
PREPARE stmt FROM 'SELECT ? AS c1 FROM DUAL';
EXECUTE stmt USING current_time;
c1
10:20:30
EXECUTE stmt USING IGNORE;
c1
NULL
DEALLOCATE PREPARE stmt;
PREPARE stmt FROM "SELECT DATE('') between''AND ? AS c1";
EXECUTE stmt USING current_time;
c1
1
Warnings:
Warning 1292 Truncated incorrect datetime value: ''
Warning 1292 Truncated incorrect datetime value: ''
EXECUTE stmt USING @unknown;
c1
NULL
Warnings:
Warning 1292 Truncated incorrect datetime value: ''
Warning 1292 Truncated incorrect datetime value: ''
DEALLOCATE PREPARE stmt;
PREPARE stmt FROM 'SELECT CONCAT(UNIX_TIMESTAMP(?)) AS c1';
EXECUTE stmt USING CURRENT_TIMESTAMP;
c1
978344430
EXECUTE stmt USING @unknown;
c1
NULL
DEALLOCATE PREPARE stmt;
SET timestamp=DEFAULT;
SET time_zone=DEFAULT;
# End of 10.5 tests

View file

@ -217,3 +217,41 @@ SELECT LEFT("12345", @@ft_boolean_syntax);
SET @@sort_buffer_size=DEFAULT;
--echo End of 5.0 tests.
--echo # Start of 10.5 tests
--echo #
--echo # MDEV-25593 Assertion `0' failed in Type_handler_temporal_result::Item_get_date on double EXECUTE
--echo #
SET time_zone='+00:00';
SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30');
PREPARE stmt FROM 'SELECT ? AS c1';
EXECUTE stmt USING current_timestamp;
EXECUTE stmt USING @unknown;
DEALLOCATE PREPARE stmt;
PREPARE stmt FROM 'SELECT ? AS c1 FROM DUAL';
EXECUTE stmt USING current_time;
EXECUTE stmt USING DEFAULT;
DEALLOCATE PREPARE stmt;
PREPARE stmt FROM 'SELECT ? AS c1 FROM DUAL';
EXECUTE stmt USING current_time;
EXECUTE stmt USING IGNORE;
DEALLOCATE PREPARE stmt;
PREPARE stmt FROM "SELECT DATE('') between''AND ? AS c1";
EXECUTE stmt USING current_time;
EXECUTE stmt USING @unknown;
DEALLOCATE PREPARE stmt;
PREPARE stmt FROM 'SELECT CONCAT(UNIX_TIMESTAMP(?)) AS c1';
EXECUTE stmt USING CURRENT_TIMESTAMP;
EXECUTE stmt USING @unknown;
DEALLOCATE PREPARE stmt;
SET timestamp=DEFAULT;
SET time_zone=DEFAULT;
--echo # End of 10.5 tests

View file

@ -0,0 +1,17 @@
# Start of 10.5 tests
#
# MDEV-35427 Assertion `is_null() >= item->null_value' failed in Timestamp_or_zero_datetime_native_null::Timestamp_or_zero_datetime_native_null on EXECUTE
#
SET time_zone='+00:00';
SET timestamp=1000000000;
PREPARE s FROM 'SELECT CONCAT (UNIX_TIMESTAMP(?))';
EXECUTE s USING CAST('::' AS INET6);
CONCAT (UNIX_TIMESTAMP(?))
999993600
EXECUTE s USING NULL;
CONCAT (UNIX_TIMESTAMP(?))
NULL
DEALLOCATE PREPARE s;
SET timestamp=DEFAULT;
SET time_zone=DEFAULT;
# End of 10.5 tests

View file

@ -0,0 +1,16 @@
--echo # Start of 10.5 tests
--echo #
--echo # MDEV-35427 Assertion `is_null() >= item->null_value' failed in Timestamp_or_zero_datetime_native_null::Timestamp_or_zero_datetime_native_null on EXECUTE
--echo #
SET time_zone='+00:00';
SET timestamp=1000000000;
PREPARE s FROM 'SELECT CONCAT (UNIX_TIMESTAMP(?))';
EXECUTE s USING CAST('::' AS INET6);
EXECUTE s USING NULL;
DEALLOCATE PREPARE s;
SET timestamp=DEFAULT;
SET time_zone=DEFAULT;
--echo # End of 10.5 tests

View file

@ -4426,6 +4426,7 @@ bool Item_param::set_from_item(THD *thd, Item *item)
if (item->null_value)
{
set_null();
set_handler(&type_handler_null);
DBUG_RETURN(false);
}
else
@ -4443,7 +4444,10 @@ bool Item_param::set_from_item(THD *thd, Item *item)
DBUG_RETURN(set_value(thd, item, &tmp, h));
}
else
{
set_null();
set_handler(&type_handler_null);
}
DBUG_RETURN(0);
}
@ -4963,7 +4967,7 @@ Item_param::set_param_type_and_swap_value(Item_param *src)
}
void Item_param::set_default()
void Item_param::set_default(bool set_type_handler_null)
{
m_is_settable_routine_parameter= false;
state= DEFAULT_VALUE;
@ -4976,13 +4980,17 @@ void Item_param::set_default()
can misbehave (e.g. crash on asserts).
*/
null_value= true;
if (set_type_handler_null)
set_handler(&type_handler_null);
}
void Item_param::set_ignore()
void Item_param::set_ignore(bool set_type_handler_null)
{
m_is_settable_routine_parameter= false;
state= IGNORE_VALUE;
null_value= true;
if (set_type_handler_null)
set_handler(&type_handler_null);
}
/**

View file

@ -4154,8 +4154,8 @@ public:
int save_in_field(Field *field, bool no_conversions) override;
void set_default();
void set_ignore();
void set_default(bool set_type_handler_null);
void set_ignore(bool set_type_handler_null);
void set_null();
void set_int(longlong i, uint32 max_length_arg);
void set_double(double i);
@ -6695,7 +6695,7 @@ public:
{
// It should not be possible to have "EXECUTE .. USING DEFAULT(a)"
DBUG_ASSERT(0);
param->set_default();
param->set_default(true);
return false;
}
table_map used_tables() const override;
@ -6826,7 +6826,7 @@ public:
}
bool save_in_param(THD *, Item_param *param) override
{
param->set_default();
param->set_default(true);
return false;
}
Item *do_get_copy(THD *thd) const override
@ -6860,7 +6860,7 @@ public:
}
bool save_in_param(THD *, Item_param *param) override
{
param->set_ignore();
param->set_ignore(true);
return false;
}

View file

@ -899,10 +899,10 @@ static bool insert_bulk_params(Prepared_statement *stmt,
param->set_null();
break;
case STMT_INDICATOR_DEFAULT:
param->set_default();
param->set_default(false);
break;
case STMT_INDICATOR_IGNORE:
param->set_ignore();
param->set_ignore(false);
break;
default:
DBUG_ASSERT(0);