diff options
author | Alexander Barkov <bar@mariadb.com> | 2019-09-24 10:46:18 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2019-09-24 10:46:18 +0400 |
commit | 67b0faa29e59387b74ae8547c96cf0f31fc3d9d1 (patch) | |
tree | c5ba41a19cf75f79b452a5d0bfa3ff60a6964f6f /mysql-test | |
parent | fd3ad41eed70e201dc6fef4d302d9e748e478358 (diff) | |
download | mariadb-git-67b0faa29e59387b74ae8547c96cf0f31fc3d9d1.tar.gz |
MDEV-20495 Assertion `precision > 0' failed in decimal_bin_size upon CREATE .. SELECT with zerofilled decimal
Also fixes:
MDEV-20560 Assertion `precision > 0' failed in decimal_bin_size upon SELECT with MOD short unsigned decimal
Changing the way how Item_func_mod calculates its max_length.
It now uses decimal_precision(), decimal_scale() and unsigned_flag
of its arguments, like all other Item_num_op descendants do.
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/r/ctype_binary.result | 2 | ||||
-rw-r--r-- | mysql-test/r/ctype_cp1251.result | 2 | ||||
-rw-r--r-- | mysql-test/r/ctype_latin1.result | 2 | ||||
-rw-r--r-- | mysql-test/r/ctype_ucs.result | 2 | ||||
-rw-r--r-- | mysql-test/r/ctype_utf8.result | 2 | ||||
-rw-r--r-- | mysql-test/r/func_math.result | 58 | ||||
-rw-r--r-- | mysql-test/r/func_time.result | 2 | ||||
-rw-r--r-- | mysql-test/r/type_newdecimal.result | 67 | ||||
-rw-r--r-- | mysql-test/t/func_math.test | 38 | ||||
-rw-r--r-- | mysql-test/t/type_newdecimal.test | 45 |
10 files changed, 214 insertions, 6 deletions
diff --git a/mysql-test/r/ctype_binary.result b/mysql-test/r/ctype_binary.result index 3fc440b8354..fd709176ea9 100644 --- a/mysql-test/r/ctype_binary.result +++ b/mysql-test/r/ctype_binary.result @@ -102,7 +102,7 @@ create table t1 as select concat(1 % 2) as c1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `c1` varbinary(1) DEFAULT NULL + `c1` varbinary(2) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; select hex(concat(-1)); diff --git a/mysql-test/r/ctype_cp1251.result b/mysql-test/r/ctype_cp1251.result index 9d5dea2f286..426a06165a7 100644 --- a/mysql-test/r/ctype_cp1251.result +++ b/mysql-test/r/ctype_cp1251.result @@ -494,7 +494,7 @@ create table t1 as select concat(1 % 2) as c1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `c1` varchar(1) CHARACTER SET cp1251 DEFAULT NULL + `c1` varchar(2) CHARACTER SET cp1251 DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; select hex(concat(-1)); diff --git a/mysql-test/r/ctype_latin1.result b/mysql-test/r/ctype_latin1.result index db9d03a8656..4273f71bac9 100644 --- a/mysql-test/r/ctype_latin1.result +++ b/mysql-test/r/ctype_latin1.result @@ -676,7 +676,7 @@ create table t1 as select concat(1 % 2) as c1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `c1` varchar(1) DEFAULT NULL + `c1` varchar(2) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; select hex(concat(-1)); diff --git a/mysql-test/r/ctype_ucs.result b/mysql-test/r/ctype_ucs.result index 1c9e31d3a06..a49050e6e94 100644 --- a/mysql-test/r/ctype_ucs.result +++ b/mysql-test/r/ctype_ucs.result @@ -1492,7 +1492,7 @@ create table t1 as select concat(1 % 2) as c1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `c1` varchar(1) CHARACTER SET ucs2 DEFAULT NULL + `c1` varchar(2) CHARACTER SET ucs2 DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; select hex(concat(-1)); diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index fee27ef177f..6829b19f59d 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -2313,7 +2313,7 @@ create table t1 as select concat(1 % 2) as c1; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `c1` varchar(1) CHARACTER SET utf8 DEFAULT NULL + `c1` varchar(2) CHARACTER SET utf8 DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; select hex(concat(-1)); diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result index 66bbb25b309..6edaa2e4d96 100644 --- a/mysql-test/r/func_math.result +++ b/mysql-test/r/func_math.result @@ -771,5 +771,63 @@ STDDEV_SAMP(ROUND('0', 309)) 0 DROP TABLE t1; # +# MDEV-20495 Assertion `precision > 0' failed in decimal_bin_size upon CREATE .. SELECT with zerofilled decimal +# +# Testing that dyadic arithmetic operations are symmetric +# for (+1) and (-1) and produce the same length in CONCAT(), +# because (+1) and (-1) have the same data type: signed int. +CREATE TABLE t1 AS SELECT +CONCAT(+1%2.0), +CONCAT(-1%2.0), +CONCAT(+1/2.0), +CONCAT(-1/2.0), +CONCAT(+1*2.0), +CONCAT(-1*2.0), +CONCAT(+1+2.0), +CONCAT(-1+2.0), +CONCAT(+1-2.0), +CONCAT(-1-2.0); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `CONCAT(+1%2.0)` varchar(4) DEFAULT NULL, + `CONCAT(-1%2.0)` varchar(4) DEFAULT NULL, + `CONCAT(+1/2.0)` varchar(8) DEFAULT NULL, + `CONCAT(-1/2.0)` varchar(8) DEFAULT NULL, + `CONCAT(+1*2.0)` varchar(5) NOT NULL DEFAULT '', + `CONCAT(-1*2.0)` varchar(5) NOT NULL DEFAULT '', + `CONCAT(+1+2.0)` varchar(5) NOT NULL DEFAULT '', + `CONCAT(-1+2.0)` varchar(5) NOT NULL DEFAULT '', + `CONCAT(+1-2.0)` varchar(5) NOT NULL DEFAULT '', + `CONCAT(-1-2.0)` varchar(5) NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 AS SELECT +CONCAT(+1%2), +CONCAT(-1%2), +CONCAT(+1/2), +CONCAT(-1/2), +CONCAT(+1*2), +CONCAT(-1*2), +CONCAT(+1+2), +CONCAT(-1+2), +CONCAT(+1-2), +CONCAT(-1-2); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `CONCAT(+1%2)` varchar(2) DEFAULT NULL, + `CONCAT(-1%2)` varchar(2) DEFAULT NULL, + `CONCAT(+1/2)` varchar(7) DEFAULT NULL, + `CONCAT(-1/2)` varchar(7) DEFAULT NULL, + `CONCAT(+1*2)` varchar(3) NOT NULL DEFAULT '', + `CONCAT(-1*2)` varchar(3) NOT NULL DEFAULT '', + `CONCAT(+1+2)` varchar(3) NOT NULL DEFAULT '', + `CONCAT(-1+2)` varchar(3) NOT NULL DEFAULT '', + `CONCAT(+1-2)` varchar(3) NOT NULL DEFAULT '', + `CONCAT(-1-2)` varchar(3) NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +# # End of 5.5 tests # diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index 9d478b10d8a..90091ac55c5 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -2100,7 +2100,7 @@ CREATE TABLE t2 AS SELECT CONCAT(FROM_UNIXTIME(CONCAT(a,'10')) MOD FROM_UNIXTIME SHOW CREATE TABLE t2; Table Create Table t2 CREATE TABLE `t2` ( - `f2` varchar(26) DEFAULT NULL + `f2` varchar(28) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 SELECT * FROM t2; f2 diff --git a/mysql-test/r/type_newdecimal.result b/mysql-test/r/type_newdecimal.result index 81d1637947c..96053e5a12c 100644 --- a/mysql-test/r/type_newdecimal.result +++ b/mysql-test/r/type_newdecimal.result @@ -2039,3 +2039,70 @@ t1 CREATE TABLE `t1` ( `1.0 * 2.000` decimal(6,4) NOT NULL DEFAULT '0.0000' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t1; +# +# MDEV-20495 Assertion `precision > 0' failed in decimal_bin_size upon CREATE .. SELECT with zerofilled decimal +# +CREATE TABLE t1 (d DECIMAL(1,0) ZEROFILL); +CREATE TABLE t2 AS SELECT 0 MOD d AS f FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `f` decimal(1,0) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2; +CREATE TABLE t1 (d DECIMAL(1,0) UNSIGNED); +CREATE TABLE t2 AS SELECT 0 MOD d AS f FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `f` decimal(1,0) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE IF EXISTS t1,t2; +CREATE TABLE t1 (d DECIMAL(1,0) ZEROFILL); +CREATE TABLE t2 AS SELECT CAST(0 AS UNSIGNED) MOD d AS f FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `f` decimal(1,0) unsigned DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2; +CREATE TABLE t1 (d DECIMAL(1,0) UNSIGNED); +CREATE TABLE t2 AS SELECT CAST(0 AS UNSIGNED) MOD d AS f FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `f` decimal(1,0) unsigned DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1,t2; +# +# MDEV-20560 Assertion `precision > 0' failed in decimal_bin_size upon SELECT with MOD short unsigned decimal +# +CREATE TABLE t1 (a DECIMAL(1,0) UNSIGNED); +INSERT INTO t1 VALUES (1.0),(2.0); +SELECT DISTINCT 1 MOD a FROM t1; +1 MOD a +0 +1 +CREATE TABLE t2 AS SELECT DISTINCT 1 MOD a AS f FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `f` decimal(1,0) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2; +CREATE TABLE t1 (a DECIMAL(1,0) UNSIGNED); +INSERT INTO t1 VALUES (1.0),(2.0); +SELECT DISTINCT 1 MOD a FROM t1; +1 MOD a +0 +1 +CREATE TABLE t2 AS SELECT DISTINCT CAST(1 AS UNSIGNED) MOD a AS f FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `f` decimal(1,0) unsigned DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2; +# +# End of 5.5 tests +# diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test index d31b33b5df9..1b5fa519c09 100644 --- a/mysql-test/t/func_math.test +++ b/mysql-test/t/func_math.test @@ -576,6 +576,44 @@ INSERT INTO t1 VALUES (1),(2); SELECT STDDEV_SAMP(ROUND('0', 309)) FROM t1; DROP TABLE t1; + +--echo # +--echo # MDEV-20495 Assertion `precision > 0' failed in decimal_bin_size upon CREATE .. SELECT with zerofilled decimal +--echo # + +--echo # Testing that dyadic arithmetic operations are symmetric +--echo # for (+1) and (-1) and produce the same length in CONCAT(), +--echo # because (+1) and (-1) have the same data type: signed int. + +CREATE TABLE t1 AS SELECT + CONCAT(+1%2.0), + CONCAT(-1%2.0), + CONCAT(+1/2.0), + CONCAT(-1/2.0), + CONCAT(+1*2.0), + CONCAT(-1*2.0), + CONCAT(+1+2.0), + CONCAT(-1+2.0), + CONCAT(+1-2.0), + CONCAT(-1-2.0); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 AS SELECT + CONCAT(+1%2), + CONCAT(-1%2), + CONCAT(+1/2), + CONCAT(-1/2), + CONCAT(+1*2), + CONCAT(-1*2), + CONCAT(+1+2), + CONCAT(-1+2), + CONCAT(+1-2), + CONCAT(-1-2); +SHOW CREATE TABLE t1; +DROP TABLE t1; + + --echo # --echo # End of 5.5 tests --echo # diff --git a/mysql-test/t/type_newdecimal.test b/mysql-test/t/type_newdecimal.test index adc8eb77198..52d014c6b5f 100644 --- a/mysql-test/t/type_newdecimal.test +++ b/mysql-test/t/type_newdecimal.test @@ -1625,3 +1625,48 @@ SHOW CREATE TABLE t1; DROP TABLE t1; +--echo # +--echo # MDEV-20495 Assertion `precision > 0' failed in decimal_bin_size upon CREATE .. SELECT with zerofilled decimal +--echo # + +CREATE TABLE t1 (d DECIMAL(1,0) ZEROFILL); +CREATE TABLE t2 AS SELECT 0 MOD d AS f FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t1, t2; + +CREATE TABLE t1 (d DECIMAL(1,0) UNSIGNED); +CREATE TABLE t2 AS SELECT 0 MOD d AS f FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE IF EXISTS t1,t2; + +CREATE TABLE t1 (d DECIMAL(1,0) ZEROFILL); +CREATE TABLE t2 AS SELECT CAST(0 AS UNSIGNED) MOD d AS f FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t1, t2; + +CREATE TABLE t1 (d DECIMAL(1,0) UNSIGNED); +CREATE TABLE t2 AS SELECT CAST(0 AS UNSIGNED) MOD d AS f FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t1,t2; + +--echo # +--echo # MDEV-20560 Assertion `precision > 0' failed in decimal_bin_size upon SELECT with MOD short unsigned decimal +--echo # + +CREATE TABLE t1 (a DECIMAL(1,0) UNSIGNED); +INSERT INTO t1 VALUES (1.0),(2.0); +SELECT DISTINCT 1 MOD a FROM t1; +CREATE TABLE t2 AS SELECT DISTINCT 1 MOD a AS f FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t1, t2; + +CREATE TABLE t1 (a DECIMAL(1,0) UNSIGNED); +INSERT INTO t1 VALUES (1.0),(2.0); +SELECT DISTINCT 1 MOD a FROM t1; +CREATE TABLE t2 AS SELECT DISTINCT CAST(1 AS UNSIGNED) MOD a AS f FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t1, t2; + +--echo # +--echo # End of 5.5 tests +--echo # |