diff options
-rw-r--r-- | mysql-test/include/ctype_numconv.inc | 11 | ||||
-rw-r--r-- | mysql-test/r/ctype_binary.result | 17 | ||||
-rw-r--r-- | mysql-test/r/ctype_cp1251.result | 17 | ||||
-rw-r--r-- | mysql-test/r/ctype_latin1.result | 17 | ||||
-rw-r--r-- | mysql-test/r/ctype_ucs.result | 17 | ||||
-rw-r--r-- | mysql-test/r/ctype_utf8.result | 17 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 2 |
7 files changed, 97 insertions, 1 deletions
diff --git a/mysql-test/include/ctype_numconv.inc b/mysql-test/include/ctype_numconv.inc index 1329bebb31f..25314d53fba 100644 --- a/mysql-test/include/ctype_numconv.inc +++ b/mysql-test/include/ctype_numconv.inc @@ -1794,6 +1794,17 @@ SELECT f1() FROM t1 LEFT JOIN (SELECT 1 AS a FROM t1 LIMIT 0) AS d ON 1 GROUP BY DROP FUNCTION f1; DROP TABLE t1; +--echo # +--echo # MDEV-5702 Incorrect results are returned with NULLIF() +--echo # +CREATE TABLE t1 (d DATE); +INSERT INTO t1 VALUES ('1999-11-11'),('2014-02-04'); +SELECT DISTINCT d, CAST(d AS CHAR), NULLIF(d,"2000-01-01") AS bad, NULLIF(CAST(d AS CHAR),"2000-01-01") AS good FROM t1; +CREATE TABLE t2 AS SELECT DISTINCT d, NULLIF(d,'2000-01-01') AS bad FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t1, t2; + + SET NAMES latin1; SET sql_mode=''; CREATE TABLE t1(a char(215) CHARACTER SET utf8 NOT NULL DEFAULT '', KEY(a)); diff --git a/mysql-test/r/ctype_binary.result b/mysql-test/r/ctype_binary.result index 3caf41af53b..73c81c4eb06 100644 --- a/mysql-test/r/ctype_binary.result +++ b/mysql-test/r/ctype_binary.result @@ -2848,6 +2848,23 @@ f1() 00:00:01 DROP FUNCTION f1; DROP TABLE t1; +# +# MDEV-5702 Incorrect results are returned with NULLIF() +# +CREATE TABLE t1 (d DATE); +INSERT INTO t1 VALUES ('1999-11-11'),('2014-02-04'); +SELECT DISTINCT d, CAST(d AS CHAR), NULLIF(d,"2000-01-01") AS bad, NULLIF(CAST(d AS CHAR),"2000-01-01") AS good FROM t1; +d CAST(d AS CHAR) bad good +1999-11-11 1999-11-11 1999-11-11 1999-11-11 +2014-02-04 2014-02-04 2014-02-04 2014-02-04 +CREATE TABLE t2 AS SELECT DISTINCT d, NULLIF(d,'2000-01-01') AS bad FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `d` date DEFAULT NULL, + `bad` varbinary(10) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2; SET NAMES latin1; SET sql_mode=''; CREATE TABLE t1(a char(215) CHARACTER SET utf8 NOT NULL DEFAULT '', KEY(a)); diff --git a/mysql-test/r/ctype_cp1251.result b/mysql-test/r/ctype_cp1251.result index 4b8a26265e3..9c7164911af 100644 --- a/mysql-test/r/ctype_cp1251.result +++ b/mysql-test/r/ctype_cp1251.result @@ -3240,6 +3240,23 @@ f1() 00:00:01 DROP FUNCTION f1; DROP TABLE t1; +# +# MDEV-5702 Incorrect results are returned with NULLIF() +# +CREATE TABLE t1 (d DATE); +INSERT INTO t1 VALUES ('1999-11-11'),('2014-02-04'); +SELECT DISTINCT d, CAST(d AS CHAR), NULLIF(d,"2000-01-01") AS bad, NULLIF(CAST(d AS CHAR),"2000-01-01") AS good FROM t1; +d CAST(d AS CHAR) bad good +1999-11-11 1999-11-11 1999-11-11 1999-11-11 +2014-02-04 2014-02-04 2014-02-04 2014-02-04 +CREATE TABLE t2 AS SELECT DISTINCT d, NULLIF(d,'2000-01-01') AS bad FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `d` date DEFAULT NULL, + `bad` varchar(10) CHARACTER SET cp1251 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2; SET NAMES latin1; SET sql_mode=''; CREATE TABLE t1(a char(215) CHARACTER SET utf8 NOT NULL DEFAULT '', KEY(a)); diff --git a/mysql-test/r/ctype_latin1.result b/mysql-test/r/ctype_latin1.result index ae6a4fd582d..11a9479afa3 100644 --- a/mysql-test/r/ctype_latin1.result +++ b/mysql-test/r/ctype_latin1.result @@ -3422,6 +3422,23 @@ f1() 00:00:01 DROP FUNCTION f1; DROP TABLE t1; +# +# MDEV-5702 Incorrect results are returned with NULLIF() +# +CREATE TABLE t1 (d DATE); +INSERT INTO t1 VALUES ('1999-11-11'),('2014-02-04'); +SELECT DISTINCT d, CAST(d AS CHAR), NULLIF(d,"2000-01-01") AS bad, NULLIF(CAST(d AS CHAR),"2000-01-01") AS good FROM t1; +d CAST(d AS CHAR) bad good +1999-11-11 1999-11-11 1999-11-11 1999-11-11 +2014-02-04 2014-02-04 2014-02-04 2014-02-04 +CREATE TABLE t2 AS SELECT DISTINCT d, NULLIF(d,'2000-01-01') AS bad FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `d` date DEFAULT NULL, + `bad` varchar(10) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2; SET NAMES latin1; SET sql_mode=''; CREATE TABLE t1(a char(215) CHARACTER SET utf8 NOT NULL DEFAULT '', KEY(a)); diff --git a/mysql-test/r/ctype_ucs.result b/mysql-test/r/ctype_ucs.result index c7e1e4e57a5..2af0b2bb509 100644 --- a/mysql-test/r/ctype_ucs.result +++ b/mysql-test/r/ctype_ucs.result @@ -4238,6 +4238,23 @@ f1() 00:00:01 DROP FUNCTION f1; DROP TABLE t1; +# +# MDEV-5702 Incorrect results are returned with NULLIF() +# +CREATE TABLE t1 (d DATE); +INSERT INTO t1 VALUES ('1999-11-11'),('2014-02-04'); +SELECT DISTINCT d, CAST(d AS CHAR), NULLIF(d,"2000-01-01") AS bad, NULLIF(CAST(d AS CHAR),"2000-01-01") AS good FROM t1; +d CAST(d AS CHAR) bad good +1999-11-11 1999-11-11 1999-11-11 1999-11-11 +2014-02-04 2014-02-04 2014-02-04 2014-02-04 +CREATE TABLE t2 AS SELECT DISTINCT d, NULLIF(d,'2000-01-01') AS bad FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `d` date DEFAULT NULL, + `bad` varchar(10) CHARACTER SET ucs2 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2; SET NAMES latin1; SET sql_mode=''; CREATE TABLE t1(a char(215) CHARACTER SET utf8 NOT NULL DEFAULT '', KEY(a)); diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index fa76cc54c39..9a6dadba1f5 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -5059,6 +5059,23 @@ f1() 00:00:01 DROP FUNCTION f1; DROP TABLE t1; +# +# MDEV-5702 Incorrect results are returned with NULLIF() +# +CREATE TABLE t1 (d DATE); +INSERT INTO t1 VALUES ('1999-11-11'),('2014-02-04'); +SELECT DISTINCT d, CAST(d AS CHAR), NULLIF(d,"2000-01-01") AS bad, NULLIF(CAST(d AS CHAR),"2000-01-01") AS good FROM t1; +d CAST(d AS CHAR) bad good +1999-11-11 1999-11-11 1999-11-11 1999-11-11 +2014-02-04 2014-02-04 2014-02-04 2014-02-04 +CREATE TABLE t2 AS SELECT DISTINCT d, NULLIF(d,'2000-01-01') AS bad FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `d` date DEFAULT NULL, + `bad` varchar(10) CHARACTER SET utf8 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2; SET NAMES latin1; SET sql_mode=''; CREATE TABLE t1(a char(215) CHARACTER SET utf8 NOT NULL DEFAULT '', KEY(a)); diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index fa67b3e6afd..fa14f7bdcf1 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -2723,13 +2723,13 @@ Item_func_nullif::fix_length_and_dec() maybe_null=1; if (args[0]) // Only false if EOM { - max_length=args[0]->max_length; decimals=args[0]->decimals; unsigned_flag= args[0]->unsigned_flag; cached_result_type= args[0]->result_type(); if (cached_result_type == STRING_RESULT && agg_arg_charsets_for_comparison(collation, args, arg_count)) return; + fix_char_length(args[0]->max_char_length()); } } |