Commit 29bbf474 authored by Alexander Barkov's avatar Alexander Barkov

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

Also fixes:

MDEV-20431 GREATEST(int_col,date_col) returns wrong results in a view
parent de0f93fb
......@@ -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
......@@ -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
#
......@@ -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
#
......@@ -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 #
......@@ -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 #
......@@ -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
......@@ -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);
......
......@@ -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);
......@@ -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);
......
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