Skip to content

Commit

Permalink
MDEV-12617 CASE and CASE-alike hybrid functions do not preserve exact…
Browse files Browse the repository at this point in the history
… data types
  • Loading branch information
Alexander Barkov committed May 4, 2017
1 parent 78a891c commit 01b308c
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 149 deletions.
211 changes: 123 additions & 88 deletions mysql-test/r/func_hybrid_type.result
Original file line number Diff line number Diff line change
Expand Up @@ -1000,14 +1000,14 @@ t2 CREATE TABLE `t2` (
`least____a_a` int(11) DEFAULT NULL,
`greatest_a_a` int(11) DEFAULT NULL,
`___________b` bit(8) DEFAULT NULL,
`case_______b` int(8) unsigned DEFAULT NULL,
`case_____b_b` int(8) unsigned DEFAULT NULL,
`coalesce___b` int(8) unsigned DEFAULT NULL,
`coalesce_b_b` int(8) unsigned DEFAULT NULL,
`if_______b_b` int(8) unsigned DEFAULT NULL,
`case_______b` bit(8) DEFAULT NULL,
`case_____b_b` bit(8) DEFAULT NULL,
`coalesce___b` bit(8) DEFAULT NULL,
`coalesce_b_b` bit(8) DEFAULT NULL,
`if_______b_b` bit(8) DEFAULT NULL,
`ifnull___b_b` bit(8) DEFAULT NULL,
`least____b_b` int(8) unsigned DEFAULT NULL,
`greatest_b_b` int(8) unsigned DEFAULT NULL
`least____b_b` bit(8) DEFAULT NULL,
`greatest_b_b` bit(8) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
Expand Down Expand Up @@ -1119,18 +1119,18 @@ GREATEST(a, b) AS greatest_a_b,
GREATEST(b, a) AS greatest_b_a
FROM t1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def case_____a_b 8 10 10 Y 32928 0 63
def case_____b_a 8 10 2 Y 32928 0 63
def coalesce_a_b 8 10 10 Y 32928 0 63
def coalesce_b_a 8 10 2 Y 32928 0 63
def if_______a_b 8 10 2 Y 32928 0 63
def if_______b_a 8 10 10 Y 32928 0 63
def ifnull___a_b 8 10 10 Y 32928 0 63
def ifnull___b_a 8 10 2 Y 32928 0 63
def least____a_b 8 10 2 Y 32928 0 63
def least____b_a 8 10 2 Y 32928 0 63
def greatest_a_b 8 10 10 Y 32928 0 63
def greatest_b_a 8 10 10 Y 32928 0 63
def case_____a_b 3 10 10 Y 32928 0 63
def case_____b_a 3 10 2 Y 32928 0 63
def coalesce_a_b 3 10 10 Y 32928 0 63
def coalesce_b_a 3 10 2 Y 32928 0 63
def if_______a_b 3 10 2 Y 32928 0 63
def if_______b_a 3 10 10 Y 32928 0 63
def ifnull___a_b 3 10 10 Y 32928 0 63
def ifnull___b_a 3 10 2 Y 32928 0 63
def least____a_b 3 10 2 Y 32928 0 63
def least____b_a 3 10 2 Y 32928 0 63
def greatest_a_b 3 10 10 Y 32928 0 63
def greatest_b_a 3 10 10 Y 32928 0 63
case_____a_b 4294967295
case_____b_a 50
coalesce_a_b 4294967295
Expand Down Expand Up @@ -1177,14 +1177,14 @@ t2 CREATE TABLE `t2` (
`least____a_a` int(10) unsigned DEFAULT NULL,
`greatest_a_a` int(10) unsigned DEFAULT NULL,
`___________b` bit(8) DEFAULT NULL,
`case_______b` int(8) unsigned DEFAULT NULL,
`case_____b_b` int(8) unsigned DEFAULT NULL,
`coalesce___b` int(8) unsigned DEFAULT NULL,
`coalesce_b_b` int(8) unsigned DEFAULT NULL,
`if_______b_b` int(8) unsigned DEFAULT NULL,
`case_______b` bit(8) DEFAULT NULL,
`case_____b_b` bit(8) DEFAULT NULL,
`coalesce___b` bit(8) DEFAULT NULL,
`coalesce_b_b` bit(8) DEFAULT NULL,
`if_______b_b` bit(8) DEFAULT NULL,
`ifnull___b_b` bit(8) DEFAULT NULL,
`least____b_b` int(8) unsigned DEFAULT NULL,
`greatest_b_b` int(8) unsigned DEFAULT NULL
`least____b_b` bit(8) DEFAULT NULL,
`greatest_b_b` bit(8) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
Expand Down Expand Up @@ -1212,8 +1212,8 @@ t2 CREATE TABLE `t2` (
`coalesce_b_a` int(10) unsigned DEFAULT NULL,
`if_______a_b` int(10) unsigned DEFAULT NULL,
`if_______b_a` int(10) unsigned DEFAULT NULL,
`ifnull___a_b` bigint(10) unsigned DEFAULT NULL,
`ifnull___b_a` bigint(10) unsigned DEFAULT NULL,
`ifnull___a_b` int(10) unsigned DEFAULT NULL,
`ifnull___b_a` int(10) unsigned DEFAULT NULL,
`least____a_b` int(10) unsigned DEFAULT NULL,
`least____b_a` int(10) unsigned DEFAULT NULL,
`greatest_a_b` int(10) unsigned DEFAULT NULL,
Expand Down Expand Up @@ -1345,23 +1345,23 @@ SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`___________a` bit(7) DEFAULT NULL,
`case_______a` int(7) unsigned DEFAULT NULL,
`case_____a_a` int(7) unsigned DEFAULT NULL,
`coalesce___a` int(7) unsigned DEFAULT NULL,
`coalesce_a_a` int(7) unsigned DEFAULT NULL,
`if_______a_a` int(7) unsigned DEFAULT NULL,
`case_______a` bit(7) DEFAULT NULL,
`case_____a_a` bit(7) DEFAULT NULL,
`coalesce___a` bit(7) DEFAULT NULL,
`coalesce_a_a` bit(7) DEFAULT NULL,
`if_______a_a` bit(7) DEFAULT NULL,
`ifnull___a_a` bit(7) DEFAULT NULL,
`least____a_a` int(7) unsigned DEFAULT NULL,
`greatest_a_a` int(7) unsigned DEFAULT NULL,
`least____a_a` bit(7) DEFAULT NULL,
`greatest_a_a` bit(7) DEFAULT NULL,
`___________b` bit(8) DEFAULT NULL,
`case_______b` int(8) unsigned DEFAULT NULL,
`case_____b_b` int(8) unsigned DEFAULT NULL,
`coalesce___b` int(8) unsigned DEFAULT NULL,
`coalesce_b_b` int(8) unsigned DEFAULT NULL,
`if_______b_b` int(8) unsigned DEFAULT NULL,
`case_______b` bit(8) DEFAULT NULL,
`case_____b_b` bit(8) DEFAULT NULL,
`coalesce___b` bit(8) DEFAULT NULL,
`coalesce_b_b` bit(8) DEFAULT NULL,
`if_______b_b` bit(8) DEFAULT NULL,
`ifnull___b_b` bit(8) DEFAULT NULL,
`least____b_b` int(8) unsigned DEFAULT NULL,
`greatest_b_b` int(8) unsigned DEFAULT NULL
`least____b_b` bit(8) DEFAULT NULL,
`greatest_b_b` bit(8) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
Expand All @@ -1383,18 +1383,18 @@ FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`case_____a_b` int(8) unsigned DEFAULT NULL,
`case_____b_a` int(8) unsigned DEFAULT NULL,
`coalesce_a_b` int(8) unsigned DEFAULT NULL,
`coalesce_b_a` int(8) unsigned DEFAULT NULL,
`if_______a_b` int(8) unsigned DEFAULT NULL,
`if_______b_a` int(8) unsigned DEFAULT NULL,
`case_____a_b` bit(8) DEFAULT NULL,
`case_____b_a` bit(8) DEFAULT NULL,
`coalesce_a_b` bit(8) DEFAULT NULL,
`coalesce_b_a` bit(8) DEFAULT NULL,
`if_______a_b` bit(8) DEFAULT NULL,
`if_______b_a` bit(8) DEFAULT NULL,
`ifnull___a_b` bit(8) DEFAULT NULL,
`ifnull___b_a` bit(8) DEFAULT NULL,
`least____a_b` int(8) unsigned DEFAULT NULL,
`least____b_a` int(8) unsigned DEFAULT NULL,
`greatest_a_b` int(8) unsigned DEFAULT NULL,
`greatest_b_a` int(8) unsigned DEFAULT NULL
`least____a_b` bit(8) DEFAULT NULL,
`least____b_a` bit(8) DEFAULT NULL,
`greatest_a_b` bit(8) DEFAULT NULL,
`greatest_b_a` bit(8) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
DROP TABLE t1;
Expand Down Expand Up @@ -1429,8 +1429,8 @@ def coalesce___a 4 12 1 Y 32896 31 63
def coalesce_a_a 4 12 1 Y 32896 31 63
def if_______a_a 4 12 1 Y 32896 31 63
def ifnull___a_a 4 12 1 Y 32896 31 63
def least____a_a 5 23 1 Y 32896 31 63
def greatest_a_a 5 23 1 Y 32896 31 63
def least____a_a 4 23 1 Y 32896 31 63
def greatest_a_a 4 23 1 Y 32896 31 63
def test t1 t1 b ___________b 2 6 6 Y 32768 0 63
def case_______b 2 6 6 Y 32896 0 63
def case_____b_b 2 6 6 Y 32896 0 63
Expand Down Expand Up @@ -1522,23 +1522,23 @@ SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`___________a` float DEFAULT NULL,
`case_______a` double DEFAULT NULL,
`case_____a_a` double DEFAULT NULL,
`coalesce___a` double DEFAULT NULL,
`coalesce_a_a` double DEFAULT NULL,
`if_______a_a` double DEFAULT NULL,
`case_______a` float DEFAULT NULL,
`case_____a_a` float DEFAULT NULL,
`coalesce___a` float DEFAULT NULL,
`coalesce_a_a` float DEFAULT NULL,
`if_______a_a` float DEFAULT NULL,
`ifnull___a_a` float DEFAULT NULL,
`least____a_a` double DEFAULT NULL,
`greatest_a_a` double DEFAULT NULL,
`least____a_a` float DEFAULT NULL,
`greatest_a_a` float DEFAULT NULL,
`___________b` smallint(6) DEFAULT NULL,
`case_______b` int(6) DEFAULT NULL,
`case_____b_b` int(6) DEFAULT NULL,
`coalesce___b` int(6) DEFAULT NULL,
`coalesce_b_b` int(6) DEFAULT NULL,
`if_______b_b` int(6) DEFAULT NULL,
`case_______b` smallint(6) DEFAULT NULL,
`case_____b_b` smallint(6) DEFAULT NULL,
`coalesce___b` smallint(6) DEFAULT NULL,
`coalesce_b_b` smallint(6) DEFAULT NULL,
`if_______b_b` smallint(6) DEFAULT NULL,
`ifnull___b_b` smallint(6) DEFAULT NULL,
`least____b_b` int(6) DEFAULT NULL,
`greatest_b_b` int(6) DEFAULT NULL
`least____b_b` smallint(6) DEFAULT NULL,
`greatest_b_b` smallint(6) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
Expand All @@ -1560,12 +1560,12 @@ FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`case_____a_b` double DEFAULT NULL,
`case_____b_a` double DEFAULT NULL,
`coalesce_a_b` double DEFAULT NULL,
`coalesce_b_a` double DEFAULT NULL,
`if_______a_b` double DEFAULT NULL,
`if_______b_a` double DEFAULT NULL,
`case_____a_b` float DEFAULT NULL,
`case_____b_a` float DEFAULT NULL,
`coalesce_a_b` float DEFAULT NULL,
`coalesce_b_a` float DEFAULT NULL,
`if_______a_b` float DEFAULT NULL,
`if_______b_a` float DEFAULT NULL,
`ifnull___a_b` float DEFAULT NULL,
`ifnull___b_a` float DEFAULT NULL,
`least____a_b` double DEFAULT NULL,
Expand Down Expand Up @@ -1885,14 +1885,14 @@ t2 CREATE TABLE `t2` (
`least____a_a` int(11) DEFAULT NULL,
`greatest_a_a` int(11) DEFAULT NULL,
`___________b` year(4) DEFAULT NULL,
`case_______b` int(4) unsigned DEFAULT NULL,
`case_____b_b` int(4) unsigned DEFAULT NULL,
`coalesce___b` int(4) unsigned DEFAULT NULL,
`coalesce_b_b` int(4) unsigned DEFAULT NULL,
`if_______b_b` int(4) unsigned DEFAULT NULL,
`case_______b` year(4) DEFAULT NULL,
`case_____b_b` year(4) DEFAULT NULL,
`coalesce___b` year(4) DEFAULT NULL,
`coalesce_b_b` year(4) DEFAULT NULL,
`if_______b_b` year(4) DEFAULT NULL,
`ifnull___b_b` year(4) DEFAULT NULL,
`least____b_b` int(4) unsigned DEFAULT NULL,
`greatest_b_b` int(4) unsigned DEFAULT NULL
`least____b_b` year(4) DEFAULT NULL,
`greatest_b_b` year(4) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
Expand Down Expand Up @@ -2062,14 +2062,14 @@ t2 CREATE TABLE `t2` (
`least____a_a` int(10) unsigned DEFAULT NULL,
`greatest_a_a` int(10) unsigned DEFAULT NULL,
`___________b` year(4) DEFAULT NULL,
`case_______b` int(4) unsigned DEFAULT NULL,
`case_____b_b` int(4) unsigned DEFAULT NULL,
`coalesce___b` int(4) unsigned DEFAULT NULL,
`coalesce_b_b` int(4) unsigned DEFAULT NULL,
`if_______b_b` int(4) unsigned DEFAULT NULL,
`case_______b` year(4) DEFAULT NULL,
`case_____b_b` year(4) DEFAULT NULL,
`coalesce___b` year(4) DEFAULT NULL,
`coalesce_b_b` year(4) DEFAULT NULL,
`if_______b_b` year(4) DEFAULT NULL,
`ifnull___b_b` year(4) DEFAULT NULL,
`least____b_b` int(4) unsigned DEFAULT NULL,
`greatest_b_b` int(4) unsigned DEFAULT NULL
`least____b_b` year(4) DEFAULT NULL,
`greatest_b_b` year(4) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2;
SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
Expand Down Expand Up @@ -3512,5 +3512,40 @@ t2 CREATE TABLE `t2` (
DROP TABLE t2;
DROP TABLE t1;
#
# MDEV-12617 CASE and CASE-alike hybrid functions do not preserve exact data types
#
CREATE TABLE t1 (a FLOAT(10,2));
CREATE TABLE t2 AS SELECT COALESCE(a) FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`COALESCE(a)` float(10,2) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2, t1;
CREATE TABLE t1 (a FLOAT(10,2));
CREATE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`LEAST(a,a)` float(19,2) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2, t1;
CREATE TABLE t1 (a TINYINT(1));
CREATE TABLE t2 AS SELECT COALESCE(a) FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`COALESCE(a)` tinyint(4) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2, t1;
CREATE TABLE t1 (a TINYINT(1));
CREATE TABLE t2 AS SELECT LEAST(a,a) FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`LEAST(a,a)` tinyint(4) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2, t1;
#
# End of 10.3 tests
#
Loading

0 comments on commit 01b308c

Please sign in to comment.