revision-id: 7bc5acf68e4908b2817c1decea8ee6210c01d91b (mariadb-10.3.6-175-g7bc5acf68e4) parent(s): 4a5e23e257e229b548599133dbed5162af9df6d9 author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2018-05-14 13:29:20 +0200 message: MDEV-15576: Server crashed in Cached_item_str::cmp / sortcmp or Assertion `item->null_value' failed in Type_handler_temporal_result::make_sort_key upon SELECT with NULLIF and ROLLUP Fixed null_value processing and is_null() usage. --- mysql-test/main/olap.result | 14 ++++++++++++++ mysql-test/main/olap.test | 17 +++++++++++++++++ sql/item_cmpfunc.cc | 2 +- sql/item_func.h | 36 ++++++++++++++++++++++++++++-------- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/mysql-test/main/olap.result b/mysql-test/main/olap.result index bcc96d4951d..6fdbe008016 100644 --- a/mysql-test/main/olap.result +++ b/mysql-test/main/olap.result @@ -816,3 +816,17 @@ a int(11) YES 0 b int(20) YES 0 DROP VIEW v1; DROP TABLE t1; +# +# MDEV-15576: Server crashed in Cached_item_str::cmp / sortcmp or +# Assertion `item->null_value' failed in +# Type_handler_temporal_result::make_sort_key upon SELECT with NULLIF +# and ROLLUP +# +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1),(2); +SELECT NULLIF( CAST( 'foo' AS DATE ), NULL & 'bar' ) AS f FROM t1 GROUP BY f WITH ROLLUP; +f +NULL +NULL +DROP TABLE t1; +# End of 10.3 Tests diff --git a/mysql-test/main/olap.test b/mysql-test/main/olap.test index 3da08581a87..74dbe8ba10b 100644 --- a/mysql-test/main/olap.test +++ b/mysql-test/main/olap.test @@ -447,3 +447,20 @@ DESC v1; DROP VIEW v1; DROP TABLE t1; + +--echo # +--echo # MDEV-15576: Server crashed in Cached_item_str::cmp / sortcmp or +--echo # Assertion `item->null_value' failed in +--echo # Type_handler_temporal_result::make_sort_key upon SELECT with NULLIF +--echo # and ROLLUP +--echo # + +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1),(2); +--disable_warnings +SELECT NULLIF( CAST( 'foo' AS DATE ), NULL & 'bar' ) AS f FROM t1 GROUP BY f WITH ROLLUP; +--enable_warnings +DROP TABLE t1; + + +--echo # End of 10.3 Tests diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index afa68fc5df3..76f4788c1cf 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -2832,7 +2832,7 @@ Item_func_nullif::time_op(MYSQL_TIME *ltime) bool Item_func_nullif::is_null() { - return (null_value= (!compare() ? 1 : args[2]->null_value)); + return (null_value= (!compare() ? 1 : args[2]->is_null())); } void Item_func_case::reorder_args(uint start) diff --git a/sql/item_func.h b/sql/item_func.h index 8504fe41f37..9544978eb31 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1615,13 +1615,35 @@ class Item_func_rollup_const :public Item_func { name= a->name; } - double val_real() { return args[0]->val_real(); } - longlong val_int() { return args[0]->val_int(); } - String *val_str(String *str) { return args[0]->val_str(str); } - my_decimal *val_decimal(my_decimal *dec) { return args[0]->val_decimal(dec); } + double val_real() + { + double res= args[0]->val_real(); + null_value= args[0]->null_value; + return res; + } + longlong val_int() + { + longlong res= args[0]->val_int(); + null_value= args[0]->null_value; + return res; + } + String *val_str(String *str) + { + String *res= args[0]->val_str(str); + null_value= args[0]->null_value; + return res; + } + my_decimal *val_decimal(my_decimal *dec) + { + my_decimal *res= args[0]->val_decimal(dec); + null_value= args[0]->null_value; + return res; + } bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) { - return args[0]->get_date(ltime, fuzzydate); + bool rc= args[0]->get_date(ltime, fuzzydate); + null_value= args[0]->null_value; + return rc; } const char *func_name() const { return "rollup_const"; } bool const_item() const { return 0; } @@ -1630,9 +1652,7 @@ class Item_func_rollup_const :public Item_func { collation= args[0]->collation; max_length= args[0]->max_length; - decimals=args[0]->decimals; - /* The item could be a NULL constant. */ - null_value= args[0]->is_null(); + decimals=args[0]->decimals; } Item *get_copy(THD *thd) { return get_item_copy<Item_func_rollup_const>(thd, this); }