Skip to content

Commit ca619ed

Browse files
committed
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
1 parent 7d7df70 commit ca619ed

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

mysql-test/main/type_timestamp.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,5 +1143,14 @@ a dt0 dt6
11431143
DROP TABLE t1;
11441144
SET time_zone=DEFAULT;
11451145
#
1146+
# 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
1147+
#
1148+
CREATE TABLE t1 (t TIMESTAMP);
1149+
INSERT INTO t1 () VALUES (),();
1150+
SELECT IF(0,t,NULL) AS f FROM t1 GROUP BY 'foo';
1151+
f
1152+
NULL
1153+
DROP TABLE t1;
1154+
#
11461155
# End of 10.4 tests
11471156
#

mysql-test/main/type_timestamp.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,16 @@ SELECT a, CAST(a AS DATETIME) AS dt0, CAST(a AS DATETIME(6)) AS dt6 FROM t1;
740740
DROP TABLE t1;
741741
SET time_zone=DEFAULT;
742742

743+
--echo #
744+
--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
745+
--echo #
746+
747+
CREATE TABLE t1 (t TIMESTAMP);
748+
INSERT INTO t1 () VALUES (),();
749+
SELECT IF(0,t,NULL) AS f FROM t1 GROUP BY 'foo';
750+
DROP TABLE t1;
751+
752+
743753
--echo #
744754
--echo # End of 10.4 tests
745755
--echo #

sql/item.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6032,6 +6032,7 @@ class Item_copy_string : public Item_copy
60326032
class Item_copy_timestamp: public Item_copy
60336033
{
60346034
Timestamp_or_zero_datetime m_value;
6035+
bool sane() const { return !null_value || m_value.is_zero_datetime(); }
60356036
public:
60366037
Item_copy_timestamp(THD *thd, Item *arg): Item_copy(thd, arg) { }
60376038
const Type_handler *type_handler() const { return &type_handler_timestamp2; }
@@ -6044,34 +6045,47 @@ class Item_copy_timestamp: public Item_copy
60446045
}
60456046
int save_in_field(Field *field, bool no_conversions)
60466047
{
6048+
DBUG_ASSERT(sane());
6049+
if (null_value)
6050+
return set_field_to_null(field);
60476051
Timestamp_or_zero_datetime_native native(m_value, decimals);
60486052
return native.save_in_field(field, decimals);
60496053
}
60506054
longlong val_int()
60516055
{
6052-
return m_value.to_datetime(current_thd).to_longlong();
6056+
DBUG_ASSERT(sane());
6057+
return null_value ? 0 :
6058+
m_value.to_datetime(current_thd).to_longlong();
60536059
}
60546060
double val_real()
60556061
{
6056-
return m_value.to_datetime(current_thd).to_double();
6062+
DBUG_ASSERT(sane());
6063+
return null_value ? 0e0 :
6064+
m_value.to_datetime(current_thd).to_double();
60576065
}
60586066
String *val_str(String *to)
60596067
{
6060-
return m_value.to_datetime(current_thd).to_string(to, decimals);
6068+
DBUG_ASSERT(sane());
6069+
return null_value ? NULL :
6070+
m_value.to_datetime(current_thd).to_string(to, decimals);
60616071
}
60626072
my_decimal *val_decimal(my_decimal *to)
60636073
{
6064-
return m_value.to_datetime(current_thd).to_decimal(to);
6074+
DBUG_ASSERT(sane());
6075+
return null_value ? NULL :
6076+
m_value.to_datetime(current_thd).to_decimal(to);
60656077
}
60666078
bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate)
60676079
{
6080+
DBUG_ASSERT(sane());
60686081
bool res= m_value.to_TIME(thd, ltime, fuzzydate);
60696082
DBUG_ASSERT(!res);
6070-
return res;
6083+
return null_value || res;
60716084
}
60726085
bool val_native(THD *thd, Native *to)
60736086
{
6074-
return m_value.to_native(to, decimals);
6087+
DBUG_ASSERT(sane());
6088+
return null_value || m_value.to_native(to, decimals);
60756089
}
60766090
Item *get_copy(THD *thd)
60776091
{ return get_item_copy<Item_copy_timestamp>(thd, this); }

0 commit comments

Comments
 (0)