Skip to content

Commit

Permalink
MDEV-15576: Server crashed in Cached_item_str::cmp / sortcmp or Asser…
Browse files Browse the repository at this point in the history
…tion `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.
  • Loading branch information
sanja-byelkin committed May 15, 2018
1 parent 8a9048b commit 0dd1ebc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
14 changes: 14 additions & 0 deletions mysql-test/main/olap.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions mysql-test/main/olap.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions sql/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,12 @@ class Item: public Value_source,
value= NULL;
return value;
}
bool get_date_from_item(Item *item, MYSQL_TIME *ltime, ulonglong fuzzydate)
{
bool rc= item->get_date(ltime, fuzzydate);
null_value= MY_TEST(rc || item->null_value);
return rc;
}
/*
This method is used if the item was not null but convertion to
TIME/DATE/DATETIME failed. We return a zero date if allowed,
Expand Down
2 changes: 1 addition & 1 deletion sql/item_cmpfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 7 additions & 10 deletions sql/item_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -1615,24 +1615,21 @@ 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() { return val_real_from_item(args[0]); }
longlong val_int() { return val_int_from_item(args[0]); }
String *val_str(String *str) { return val_str_from_item(args[0], str); }
my_decimal *val_decimal(my_decimal *dec)
{ return val_decimal_from_item(args[0], dec); }
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{
return args[0]->get_date(ltime, fuzzydate);
}
{ return get_date_from_item(args[0], ltime, fuzzydate); }
const char *func_name() const { return "rollup_const"; }
bool const_item() const { return 0; }
const Type_handler *type_handler() const { return args[0]->type_handler(); }
void fix_length_and_dec()
{
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); }
Expand Down

0 comments on commit 0dd1ebc

Please sign in to comment.