Commit a659291e authored by Alexander Barkov's avatar Alexander Barkov

MDEV-11586 UNION of FLOAT type results in erroneous precision

Fixing the asymmetry in the array field_types_merge_rules[][]
which caused data loss when mixing FLOAT + BIGINT in UNIONs
or hybrid functions:

1. FLOAT  + INT    = DOUBLE
2. FLOAT  + BIGINT = FLOAT
3. INT    + FLOAT  = DOUBLE
4. BIGINT + FLOAT  = DOUBLE

Now FLOAT + BIGINT (as in #2) also produces DOUBLE, like the cases #1,#3,#4 do.
parent 3557de68
......@@ -772,5 +772,31 @@ t1 CREATE TABLE `t1` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table if exists t1;
#
# MDEV-11586 UNION of FLOAT type results in erroneous precision
#
CREATE TABLE t1 (f FLOAT);
INSERT INTO t1 VALUES (1.1);
SELECT f FROM t1 UNION SELECT 1;
f
1.100000023841858
1
SELECT 1 UNION SELECT f FROM t1;
1
1
1.100000023841858
SELECT f FROM t1 UNION SELECT 2147483647;
f
1.100000023841858
2147483647
SELECT 2147483647 UNION SELECT f FROM t1;
2147483647
2147483647
1.100000023841858
SELECT CASE WHEN 0 THEN (SELECT f FROM t1) ELSE 2147483647 END AS c1,
CASE WHEN 1 THEN 2147483647 ELSE (SELECT f FROM t1) END AS c2;
c1 c2
2147483647 2147483647
DROP TABLE t1;
#
# End of 10.2 tests
#
......@@ -533,6 +533,21 @@ show create table t1;
drop table if exists t1;
--echo #
--echo # MDEV-11586 UNION of FLOAT type results in erroneous precision
--echo #
CREATE TABLE t1 (f FLOAT);
INSERT INTO t1 VALUES (1.1);
SELECT f FROM t1 UNION SELECT 1;
SELECT 1 UNION SELECT f FROM t1;
SELECT f FROM t1 UNION SELECT 2147483647;
SELECT 2147483647 UNION SELECT f FROM t1;
SELECT CASE WHEN 0 THEN (SELECT f FROM t1) ELSE 2147483647 END AS c1,
CASE WHEN 1 THEN 2147483647 ELSE (SELECT f FROM t1) END AS c2;
DROP TABLE t1;
--echo #
--echo # End of 10.2 tests
--echo #
......@@ -231,7 +231,7 @@ static enum_field_types field_types_merge_rules [FIELDTYPE_NUM][FIELDTYPE_NUM]=
//MYSQL_TYPE_NULL MYSQL_TYPE_TIMESTAMP
MYSQL_TYPE_FLOAT, MYSQL_TYPE_VARCHAR,
//MYSQL_TYPE_LONGLONG MYSQL_TYPE_INT24
MYSQL_TYPE_FLOAT, MYSQL_TYPE_FLOAT,
MYSQL_TYPE_DOUBLE, MYSQL_TYPE_FLOAT,
//MYSQL_TYPE_DATE MYSQL_TYPE_TIME
MYSQL_TYPE_VARCHAR, MYSQL_TYPE_VARCHAR,
//MYSQL_TYPE_DATETIME MYSQL_TYPE_YEAR
......
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