Commit ca619ed1 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-18072 Assertion `is_null() == item->null_value || conv' failed in...

MDEV-18072 Assertion `is_null() == item->null_value || conv' failed in Timestamp_or_zero_datetime_native_null::Timestamp_or_zero_datetime_native_null upon query with GROUP BY
parent 7d7df70c
......@@ -1143,5 +1143,14 @@ a dt0 dt6
DROP TABLE t1;
SET time_zone=DEFAULT;
#
# MDEV-18072 Assertion `is_null() == item->null_value || conv' failed in Timestamp_or_zero_datetime_native_null::Timestamp_or_zero_datetime_native_null upon query with GROUP BY
#
CREATE TABLE t1 (t TIMESTAMP);
INSERT INTO t1 () VALUES (),();
SELECT IF(0,t,NULL) AS f FROM t1 GROUP BY 'foo';
f
NULL
DROP TABLE t1;
#
# End of 10.4 tests
#
......@@ -740,6 +740,16 @@ SELECT a, CAST(a AS DATETIME) AS dt0, CAST(a AS DATETIME(6)) AS dt6 FROM t1;
DROP TABLE t1;
SET time_zone=DEFAULT;
--echo #
--echo # MDEV-18072 Assertion `is_null() == item->null_value || conv' failed in Timestamp_or_zero_datetime_native_null::Timestamp_or_zero_datetime_native_null upon query with GROUP BY
--echo #
CREATE TABLE t1 (t TIMESTAMP);
INSERT INTO t1 () VALUES (),();
SELECT IF(0,t,NULL) AS f FROM t1 GROUP BY 'foo';
DROP TABLE t1;
--echo #
--echo # End of 10.4 tests
--echo #
......@@ -6032,6 +6032,7 @@ class Item_copy_string : public Item_copy
class Item_copy_timestamp: public Item_copy
{
Timestamp_or_zero_datetime m_value;
bool sane() const { return !null_value || m_value.is_zero_datetime(); }
public:
Item_copy_timestamp(THD *thd, Item *arg): Item_copy(thd, arg) { }
const Type_handler *type_handler() const { return &type_handler_timestamp2; }
......@@ -6044,34 +6045,47 @@ class Item_copy_timestamp: public Item_copy
}
int save_in_field(Field *field, bool no_conversions)
{
DBUG_ASSERT(sane());
if (null_value)
return set_field_to_null(field);
Timestamp_or_zero_datetime_native native(m_value, decimals);
return native.save_in_field(field, decimals);
}
longlong val_int()
{
return m_value.to_datetime(current_thd).to_longlong();
DBUG_ASSERT(sane());
return null_value ? 0 :
m_value.to_datetime(current_thd).to_longlong();
}
double val_real()
{
return m_value.to_datetime(current_thd).to_double();
DBUG_ASSERT(sane());
return null_value ? 0e0 :
m_value.to_datetime(current_thd).to_double();
}
String *val_str(String *to)
{
return m_value.to_datetime(current_thd).to_string(to, decimals);
DBUG_ASSERT(sane());
return null_value ? NULL :
m_value.to_datetime(current_thd).to_string(to, decimals);
}
my_decimal *val_decimal(my_decimal *to)
{
return m_value.to_datetime(current_thd).to_decimal(to);
DBUG_ASSERT(sane());
return null_value ? NULL :
m_value.to_datetime(current_thd).to_decimal(to);
}
bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate)
{
DBUG_ASSERT(sane());
bool res= m_value.to_TIME(thd, ltime, fuzzydate);
DBUG_ASSERT(!res);
return res;
return null_value || res;
}
bool val_native(THD *thd, Native *to)
{
return m_value.to_native(to, decimals);
DBUG_ASSERT(sane());
return null_value || m_value.to_native(to, decimals);
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_copy_timestamp>(thd, this); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment