Commit 0dd1ebcb authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

MDEV-15576: Server crashed in Cached_item_str::cmp / sortcmp or Assertion...

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.
parent 8a9048bc
......@@ -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
......@@ -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
......@@ -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,
......
......@@ -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)
......
......@@ -1615,14 +1615,13 @@ 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(); }
......@@ -1630,9 +1629,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); }
......
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