Commit 154ec0f4 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-6993 Bad results with join comparing DECIMAL and ENUM/SET columns

parent 55dd89e9
......@@ -2046,5 +2046,39 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL id 6 NULL 16 Using where; Using index
DROP TABLE t1;
#
# MDEV-6993 Bad results with join comparing DECIMAL and ENUM/SET columns
#
CREATE TABLE t1 (c1 DECIMAL(10,1) PRIMARY KEY);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (c1 ENUM('a','b'));
INSERT INTO t2 VALUES ('a'),('b');
SELECT t1.* FROM t1 NATURAL JOIN t2;
c1
1.0
2.0
ALTER TABLE t2 ADD PRIMARY KEY(c1);
SELECT t1.* FROM t1 NATURAL JOIN t2;
c1
1.0
2.0
SELECT t1.* FROM t1 LEFT OUTER JOIN t2 USING (c1);
c1
1.0
2.0
DROP TABLE t1,t2;
CREATE TABLE t1 (a DECIMAL(10,1), b ENUM('1','2'));
INSERT INTO t1 (a) VALUES (1),(2);
UPDATE t1 SET b=a;
SELECT * FROM t1;
a b
1.0 1
2.0 2
ALTER TABLE t1 MODIFY a ENUM('1','2');
SELECT * FROM t1;
a b
1 1
2 2
DROP TABLE t1;
#
# End of 10.0 tests
#
......
......@@ -227,5 +227,39 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index PRIMARY PRIMARY 1 NULL 2 Using where; Using index
DROP TABLE IF EXISTS t1,t2;
#
# MDEV-6993 Bad results with join comparing DECIMAL and ENUM/SET columns
#
CREATE TABLE t1 (c1 DECIMAL(10,1) PRIMARY KEY);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (c1 SET('a','b'));
INSERT INTO t2 VALUES ('a'),('b');
SELECT t1.* FROM t1 NATURAL JOIN t2;
c1
1.0
2.0
ALTER TABLE t2 ADD PRIMARY KEY(c1);
SELECT t1.* FROM t1 NATURAL JOIN t2;
c1
1.0
2.0
SELECT t1.* FROM t1 LEFT OUTER JOIN t2 USING (c1);
c1
1.0
2.0
DROP TABLE t1,t2;
CREATE TABLE t1 (a DECIMAL(10,1), b SET('1','2'));
INSERT INTO t1 (a) VALUES (1),(2);
UPDATE t1 SET b=a;
SELECT * FROM t1;
a b
1.0 1
2.0 2
ALTER TABLE t1 MODIFY a SET('1','2');
SELECT * FROM t1;
a b
1 1
2 2
DROP TABLE t1;
#
# End of 10.0 tests
#
......@@ -333,6 +333,27 @@ SELECT id,MIN(a),MAX(a) FROM t1 WHERE a<=3 GROUP BY id;
EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a<=3 GROUP BY id;
DROP TABLE t1;
--echo #
--echo # MDEV-6993 Bad results with join comparing DECIMAL and ENUM/SET columns
--echo #
CREATE TABLE t1 (c1 DECIMAL(10,1) PRIMARY KEY);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (c1 ENUM('a','b'));
INSERT INTO t2 VALUES ('a'),('b');
SELECT t1.* FROM t1 NATURAL JOIN t2;
ALTER TABLE t2 ADD PRIMARY KEY(c1);
SELECT t1.* FROM t1 NATURAL JOIN t2;
SELECT t1.* FROM t1 LEFT OUTER JOIN t2 USING (c1);
DROP TABLE t1,t2;
CREATE TABLE t1 (a DECIMAL(10,1), b ENUM('1','2'));
INSERT INTO t1 (a) VALUES (1),(2);
UPDATE t1 SET b=a;
SELECT * FROM t1;
ALTER TABLE t1 MODIFY a ENUM('1','2');
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # End of 10.0 tests
--echo #
......
......@@ -161,6 +161,27 @@ SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.c1 COLLATE latin1_swedish_ci=t2.c1;
DROP TABLE IF EXISTS t1,t2;
--echo #
--echo # MDEV-6993 Bad results with join comparing DECIMAL and ENUM/SET columns
--echo #
CREATE TABLE t1 (c1 DECIMAL(10,1) PRIMARY KEY);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (c1 SET('a','b'));
INSERT INTO t2 VALUES ('a'),('b');
SELECT t1.* FROM t1 NATURAL JOIN t2;
ALTER TABLE t2 ADD PRIMARY KEY(c1);
SELECT t1.* FROM t1 NATURAL JOIN t2;
SELECT t1.* FROM t1 LEFT OUTER JOIN t2 USING (c1);
DROP TABLE t1,t2;
CREATE TABLE t1 (a DECIMAL(10,1), b SET('1','2'));
INSERT INTO t1 (a) VALUES (1),(2);
UPDATE t1 SET b=a;
SELECT * FROM t1;
ALTER TABLE t1 MODIFY a SET('1','2');
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # End of 10.0 tests
--echo #
......@@ -792,6 +792,10 @@ Copy_field::get_copy_func(Field *to,Field *from)
else if (to->real_type() != from->real_type() ||
to_length != from_length)
{
if ((to->real_type() == MYSQL_TYPE_ENUM ||
to->real_type() == MYSQL_TYPE_SET) &&
from->real_type() == MYSQL_TYPE_NEWDECIMAL)
return do_field_decimal;
if (to->real_type() == MYSQL_TYPE_DECIMAL ||
to->result_type() == STRING_RESULT)
return do_field_string;
......
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