Commit 1081e403 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-5702 Incorrect results are returned with NULLIF()

parent 968f4d4e
......@@ -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));
......
......@@ -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));
......
......@@ -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));
......
......@@ -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));
......
......@@ -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));
......
......@@ -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));
......
......@@ -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());
}
}
......
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