diff --git a/mysql-test/r/ctype_binary.result b/mysql-test/r/ctype_binary.result index 0e8fe328589..d79265b29c7 100644 --- a/mysql-test/r/ctype_binary.result +++ b/mysql-test/r/ctype_binary.result @@ -1425,7 +1425,7 @@ create table t1 as select concat(time_to_sec('10:11:12')) as c1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `c1` varbinary(10) NOT NULL DEFAULT '' + `c1` varbinary(10) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; select hex(concat(extract(year from 20090702))); diff --git a/mysql-test/r/ctype_cp1251.result b/mysql-test/r/ctype_cp1251.result index b1e9ff38d26..babed8951a2 100644 --- a/mysql-test/r/ctype_cp1251.result +++ b/mysql-test/r/ctype_cp1251.result @@ -1507,7 +1507,7 @@ create table t1 as select concat(time_to_sec('10:11:12')) as c1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `c1` varchar(10) CHARACTER SET cp1251 NOT NULL DEFAULT '' + `c1` varchar(10) CHARACTER SET cp1251 DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; select hex(concat(extract(year from 20090702))); diff --git a/mysql-test/r/ctype_latin1.result b/mysql-test/r/ctype_latin1.result index 6216819d172..6edddecb88f 100644 --- a/mysql-test/r/ctype_latin1.result +++ b/mysql-test/r/ctype_latin1.result @@ -1835,7 +1835,7 @@ create table t1 as select concat(time_to_sec('10:11:12')) as c1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `c1` varchar(10) NOT NULL DEFAULT '' + `c1` varchar(10) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; select hex(concat(extract(year from 20090702))); diff --git a/mysql-test/r/ctype_ucs.result b/mysql-test/r/ctype_ucs.result index c2fb90ecfa6..1008f201366 100644 --- a/mysql-test/r/ctype_ucs.result +++ b/mysql-test/r/ctype_ucs.result @@ -2667,7 +2667,7 @@ create table t1 as select concat(time_to_sec('10:11:12')) as c1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `c1` varchar(10) CHARACTER SET ucs2 NOT NULL DEFAULT '' + `c1` varchar(10) CHARACTER SET ucs2 DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; select hex(concat(extract(year from 20090702))); diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index e14b54b59a3..122d722be71 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -3511,7 +3511,7 @@ create table t1 as select concat(time_to_sec('10:11:12')) as c1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `c1` varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '' + `c1` varchar(10) CHARACTER SET utf8 DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; select hex(concat(extract(year from 20090702))); diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index f1b2196ebfa..0ed46ba270b 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -1315,6 +1315,20 @@ SELECT 1 FROM t1 ORDER BY @x:=makedate(a,a); 1 1 DROP TABLE t1; +# +# Bug #52160: crash and inconsistent results when grouping +# by a function and column +# +CREATE TABLE t1(a CHAR(10) NOT NULL); +INSERT INTO t1 VALUES (''),(''); +SELECT COUNT(*) FROM t1 GROUP BY TIME_TO_SEC(a); +COUNT(*) +2 +Warnings: +Warning 1292 Truncated incorrect time value: '' +Warning 1292 Truncated incorrect time value: '' +Warning 1292 Truncated incorrect time value: '' +DROP TABLE t1; End of 5.1 tests # # Bug#57039: constant subtime expression returns incorrect result. diff --git a/mysql-test/r/type_blob.result b/mysql-test/r/type_blob.result index 78f31286ea7..e3363fcabf9 100644 --- a/mysql-test/r/type_blob.result +++ b/mysql-test/r/type_blob.result @@ -975,4 +975,14 @@ SELECT LENGTH(c) FROM t2; LENGTH(c) 65535 DROP TABLE t1, t2; +# Bug #52160: crash and inconsistent results when grouping +# by a function and column +CREATE FUNCTION f1() RETURNS TINYBLOB RETURN 1; +CREATE TABLE t1(a CHAR(1)); +INSERT INTO t1 VALUES ('0'), ('0'); +SELECT COUNT(*) FROM t1 GROUP BY f1(), a; +COUNT(*) +2 +DROP FUNCTION f1; +DROP TABLE t1; End of 5.1 tests diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index 08c09adb093..0a2b473ca59 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -832,6 +832,16 @@ INSERT INTO t1 VALUES (0),(9.216e-096); SELECT 1 FROM t1 ORDER BY @x:=makedate(a,a); DROP TABLE t1; +--echo # +--echo # Bug #52160: crash and inconsistent results when grouping +--echo # by a function and column +--echo # + +CREATE TABLE t1(a CHAR(10) NOT NULL); +INSERT INTO t1 VALUES (''),(''); +SELECT COUNT(*) FROM t1 GROUP BY TIME_TO_SEC(a); +DROP TABLE t1; + --echo End of 5.1 tests --echo # diff --git a/mysql-test/t/type_blob.test b/mysql-test/t/type_blob.test index c06d8ac97e0..fa67afa48e8 100644 --- a/mysql-test/t/type_blob.test +++ b/mysql-test/t/type_blob.test @@ -617,4 +617,17 @@ SELECT LENGTH(c) FROM t2; DROP TABLE t1, t2; +--echo # Bug #52160: crash and inconsistent results when grouping +--echo # by a function and column + +CREATE FUNCTION f1() RETURNS TINYBLOB RETURN 1; + +CREATE TABLE t1(a CHAR(1)); +INSERT INTO t1 VALUES ('0'), ('0'); + +SELECT COUNT(*) FROM t1 GROUP BY f1(), a; + +DROP FUNCTION f1; +DROP TABLE t1; + --echo End of 5.1 tests diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 004eb83cbeb..72a5aa0c296 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -361,6 +361,7 @@ public: const char *func_name() const { return "time_to_sec"; } void fix_length_and_dec() { + maybe_null= TRUE; decimals=0; max_length=10*MY_CHARSET_BIN_MB_MAXLEN; } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 2a2fe3eb36f..d521abd51a3 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -15218,6 +15218,8 @@ calc_group_buffer(JOIN *join,ORDER *group) { key_length+= 8; } + else if (type == MYSQL_TYPE_BLOB) + key_length+= MAX_BLOB_WIDTH; // Can't be used as a key else { /*