Skip to content

Commit

Permalink
MDEV-19699 Server crashes in Item_null_result::field_type upon SELECT…
Browse files Browse the repository at this point in the history
… with ROLLUP on constant table

Also fixes:

MDEV-20431 GREATEST(int_col,date_col) returns wrong results in a view
  • Loading branch information
abarkov committed Aug 27, 2019
1 parent de0f93f commit 29bbf47
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 0 deletions.
33 changes: 33 additions & 0 deletions mysql-test/r/type_date.result
Original file line number Diff line number Diff line change
Expand Up @@ -863,12 +863,14 @@ SELECT group_concat(d1/(CASE 'b' WHEN 'j' THEN 'c' END))
FROM v1 GROUP BY greatest(pk, 0, d2);
group_concat(d1/(CASE 'b' WHEN 'j' THEN 'c' END))
NULL
NULL
Warnings:
Warning 1292 Incorrect datetime value: '1' for column 'pk' at row 1
Warning 1292 Incorrect datetime value: '2' for column 'pk' at row 1
Warning 1292 Incorrect datetime value: '1' for column 'pk' at row 1
Warning 1292 Incorrect datetime value: '1' for column 'pk' at row 1
Warning 1292 Incorrect datetime value: '2' for column 'pk' at row 2
Warning 1292 Incorrect datetime value: '2' for column 'pk' at row 2
CREATE TABLE t2 AS SELECT greatest(pk, 0, d2) AS c1 FROM t1 LIMIT 0;
SHOW CREATE TABLE t2;
Table Create Table
Expand All @@ -879,5 +881,36 @@ DROP TABLE t2;
DROP VIEW v1;
DROP TABLE t1;
#
# MDEV-19699 Server crashes in Item_null_result::field_type upon SELECT with ROLLUP on constant table
#
CREATE TABLE t1 (d DATE) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('1999-11-04');
SELECT d FROM t1 GROUP BY d WITH ROLLUP HAVING d > '1990-01-01';
d
1999-11-04
DROP TABLE t1;
#
# MDEV-20431 GREATEST(int_col,date_col) returns wrong results in a view
#
CREATE TABLE t1 (pk INT NOT NULL, d DATE NOT NULL);
CREATE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 VALUES (1,'2018-06-22'),(2,'2018-07-11');
SELECT GREATEST(pk, d) FROM t1;
GREATEST(pk, d)
2018-06-22
2018-07-11
Warnings:
Warning 1292 Incorrect datetime value: '1' for column 'pk' at row 1
Warning 1292 Incorrect datetime value: '2' for column 'pk' at row 2
SELECT GREATEST(pk, d) FROM v1;
GREATEST(pk, d)
2018-06-22
2018-07-11
Warnings:
Warning 1292 Incorrect datetime value: '1' for column 'pk' at row 1
Warning 1292 Incorrect datetime value: '2' for column 'pk' at row 2
DROP VIEW v1;
DROP TABLE t1;
#
# End of 10.1 tests
#
31 changes: 31 additions & 0 deletions mysql-test/r/type_datetime.result
Original file line number Diff line number Diff line change
Expand Up @@ -1167,5 +1167,36 @@ INSERT INTO t2 SELECT * FROM t1;
DROP TABLE t1, t2;
SET SQL_MODE=DEFAULT;
#
# MDEV-19699 Server crashes in Item_null_result::field_type upon SELECT with ROLLUP on constant table
#
CREATE TABLE t1 (d DATETIME) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('1999-11-04');
SELECT d FROM t1 GROUP BY d WITH ROLLUP HAVING d > '1990-01-01';
d
1999-11-04 00:00:00
DROP TABLE t1;
#
# MDEV-20431 GREATEST(int_col,date_col) returns wrong results in a view
#
CREATE TABLE t1 (pk INT NOT NULL, d DATETIME NOT NULL);
CREATE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 VALUES (1,'2018-06-22 00:00:00'),(2,'2018-07-11 00:00:00');
SELECT GREATEST(pk, d) FROM t1;
GREATEST(pk, d)
2018-06-22 00:00:00
2018-07-11 00:00:00
Warnings:
Warning 1292 Incorrect datetime value: '1' for column 'pk' at row 1
Warning 1292 Incorrect datetime value: '2' for column 'pk' at row 2
SELECT GREATEST(pk, d) FROM v1;
GREATEST(pk, d)
2018-06-22 00:00:00
2018-07-11 00:00:00
Warnings:
Warning 1292 Incorrect datetime value: '1' for column 'pk' at row 1
Warning 1292 Incorrect datetime value: '2' for column 'pk' at row 2
DROP VIEW v1;
DROP TABLE t1;
#
# End of 10.1 tests
#
24 changes: 24 additions & 0 deletions mysql-test/t/type_date.test
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,30 @@ DROP TABLE t2;
DROP VIEW v1;
DROP TABLE t1;


--echo #
--echo # MDEV-19699 Server crashes in Item_null_result::field_type upon SELECT with ROLLUP on constant table
--echo #

CREATE TABLE t1 (d DATE) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('1999-11-04');
SELECT d FROM t1 GROUP BY d WITH ROLLUP HAVING d > '1990-01-01';
DROP TABLE t1;


--echo #
--echo # MDEV-20431 GREATEST(int_col,date_col) returns wrong results in a view
--echo #

CREATE TABLE t1 (pk INT NOT NULL, d DATE NOT NULL);
CREATE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 VALUES (1,'2018-06-22'),(2,'2018-07-11');
SELECT GREATEST(pk, d) FROM t1;
SELECT GREATEST(pk, d) FROM v1;
DROP VIEW v1;
DROP TABLE t1;


--echo #
--echo # End of 10.1 tests
--echo #
23 changes: 23 additions & 0 deletions mysql-test/t/type_datetime.test
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,29 @@ DROP TABLE t1, t2;
SET SQL_MODE=DEFAULT;


--echo #
--echo # MDEV-19699 Server crashes in Item_null_result::field_type upon SELECT with ROLLUP on constant table
--echo #

CREATE TABLE t1 (d DATETIME) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('1999-11-04');
SELECT d FROM t1 GROUP BY d WITH ROLLUP HAVING d > '1990-01-01';
DROP TABLE t1;


--echo #
--echo # MDEV-20431 GREATEST(int_col,date_col) returns wrong results in a view
--echo #

CREATE TABLE t1 (pk INT NOT NULL, d DATETIME NOT NULL);
CREATE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 VALUES (1,'2018-06-22 00:00:00'),(2,'2018-07-11 00:00:00');
SELECT GREATEST(pk, d) FROM t1;
SELECT GREATEST(pk, d) FROM v1;
DROP VIEW v1;
DROP TABLE t1;


--echo #
--echo # End of 10.1 tests
--echo #
32 changes: 32 additions & 0 deletions sql/item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3131,6 +3131,20 @@ my_decimal *Item_null::val_decimal(my_decimal *decimal_value)
}


longlong Item_null::val_datetime_packed()
{
null_value= true;
return 0;
}


longlong Item_null::val_time_packed()
{
null_value= true;
return 0;
}


bool Item_null::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{
// following assert is redundant, because fixed=1 assigned in constructor
Expand Down Expand Up @@ -7296,6 +7310,24 @@ bool Item_ref::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate)
}


longlong Item_ref::val_datetime_packed()
{
DBUG_ASSERT(fixed);
longlong tmp= (*ref)->val_datetime_packed();
null_value= (*ref)->null_value;
return tmp;
}


longlong Item_ref::val_time_packed()
{
DBUG_ASSERT(fixed);
longlong tmp= (*ref)->val_time_packed();
null_value= (*ref)->null_value;
return tmp;
}


my_decimal *Item_ref::val_decimal(my_decimal *decimal_value)
{
my_decimal *val= (*ref)->val_decimal_result(decimal_value);
Expand Down
4 changes: 4 additions & 0 deletions sql/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -2627,6 +2627,8 @@ class Item_null :public Item_basic_constant
String *val_str(String *str);
my_decimal *val_decimal(my_decimal *);
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
longlong val_datetime_packed();
longlong val_time_packed();
int save_in_field(Field *field, bool no_conversions);
int save_safe_in_field(Field *field);
bool send(Protocol *protocol, String *str);
Expand Down Expand Up @@ -3971,6 +3973,8 @@ class Item_ref :public Item_ident
String *val_str(String* tmp);
bool is_null();
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
longlong val_datetime_packed();
longlong val_time_packed();
double val_result();
longlong val_int_result();
String *str_result(String* tmp);
Expand Down

0 comments on commit 29bbf47

Please sign in to comment.