[Commits] 1a8c82161aa: MDEV-13232: Assertion `(&(&share->intern_lock)->m_mutex)->count > 0 && pthread_equal(pthread_self(), (&(&share->intern_lock)->m_mutex)->thread)' failed in _ma_state_info_write

Oleksandr Byelkin sanja at mariadb.com
Tue Apr 17 01:13:07 EEST 2018


revision-id: 1a8c82161aa2924c2bf368d376b967212f0d824f (mariadb-10.3.5-144-g1a8c82161aa)
parent(s): 65eefcdc601ef0f57b0779f1722161fc83a571c3
author: Oleksandr Byelkin
committer: Oleksandr Byelkin
timestamp: 2018-04-17 00:13:07 +0200
message:

MDEV-13232: Assertion `(&(&share->intern_lock)->m_mutex)->count > 0 && pthread_equal(pthread_self(), (&(&share->intern_lock)->m_mutex)->thread)' failed in _ma_state_info_write

Length of numegic function results limited by matsimum really possible length.

(Problem was that negation did not limited it and then was not possible to create so long field)

---
 mysql-test/main/cast.result                        |   2 +-
 mysql-test/main/ctype_binary.result                |  12 +-
 mysql-test/main/ctype_cp1251.result                |  12 +-
 mysql-test/main/ctype_latin1.result                |  12 +-
 mysql-test/main/ctype_ucs.result                   |  12 +-
 mysql-test/main/ctype_utf8.result                  |  12 +-
 mysql-test/main/metadata.result                    |  12 +-
 mysql-test/main/union.result                       | 502 +++++++++++++++++++++
 mysql-test/main/union.test                         | 260 +++++++++++
 .../suite/rpl/r/rpl_row_create_select.result       |   4 +-
 sql/item.h                                         |   5 +
 sql/item_func.cc                                   |  13 +
 sql/item_func.h                                    |  10 +-
 13 files changed, 828 insertions(+), 40 deletions(-)

diff --git a/mysql-test/main/cast.result b/mysql-test/main/cast.result
index ca314573581..72e5608ca40 100644
--- a/mysql-test/main/cast.result
+++ b/mysql-test/main/cast.result
@@ -761,7 +761,7 @@ Warning	1292	Truncated incorrect INTEGER value: '9999999999999999999999999999999
 SHOW CREATE TABLE t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `CONCAT(CAST(REPEAT('9', 1000) AS SIGNED))` varchar(21) NOT NULL,
+  `CONCAT(CAST(REPEAT('9', 1000) AS SIGNED))` varchar(20) NOT NULL,
   `CONCAT(CAST(REPEAT('9', 1000) AS UNSIGNED))` varchar(20) NOT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 DROP TABLE t1;
diff --git a/mysql-test/main/ctype_binary.result b/mysql-test/main/ctype_binary.result
index 0afe5298411..a2a24873399 100644
--- a/mysql-test/main/ctype_binary.result
+++ b/mysql-test/main/ctype_binary.result
@@ -132,7 +132,7 @@ create table t1 as select concat(1|2) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varbinary(21) DEFAULT NULL
+  `c1` varbinary(20) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(1&2));
@@ -142,7 +142,7 @@ create table t1 as select concat(1&2) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varbinary(21) DEFAULT NULL
+  `c1` varbinary(20) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(bit_count(12)));
@@ -162,7 +162,7 @@ create table t1 as select concat(2<<1) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varbinary(21) DEFAULT NULL
+  `c1` varbinary(20) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(2>>1));
@@ -172,7 +172,7 @@ create table t1 as select concat(2>>1) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varbinary(21) DEFAULT NULL
+  `c1` varbinary(20) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(~0));
@@ -182,7 +182,7 @@ create table t1 as select concat(~0) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varbinary(21) DEFAULT NULL
+  `c1` varbinary(20) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(3^2));
@@ -192,7 +192,7 @@ create table t1 as select concat(3^2) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varbinary(21) DEFAULT NULL
+  `c1` varbinary(20) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(abs(-2)));
diff --git a/mysql-test/main/ctype_cp1251.result b/mysql-test/main/ctype_cp1251.result
index 2da53740619..f86facdf01b 100644
--- a/mysql-test/main/ctype_cp1251.result
+++ b/mysql-test/main/ctype_cp1251.result
@@ -541,7 +541,7 @@ create table t1 as select concat(1|2) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET cp1251 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET cp1251 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(1&2));
@@ -551,7 +551,7 @@ create table t1 as select concat(1&2) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET cp1251 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET cp1251 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(bit_count(12)));
@@ -571,7 +571,7 @@ create table t1 as select concat(2<<1) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET cp1251 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET cp1251 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(2>>1));
@@ -581,7 +581,7 @@ create table t1 as select concat(2>>1) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET cp1251 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET cp1251 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(~0));
@@ -591,7 +591,7 @@ create table t1 as select concat(~0) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET cp1251 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET cp1251 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(3^2));
@@ -601,7 +601,7 @@ create table t1 as select concat(3^2) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET cp1251 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET cp1251 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(abs(-2)));
diff --git a/mysql-test/main/ctype_latin1.result b/mysql-test/main/ctype_latin1.result
index d5906cb74dd..97761e6ceec 100644
--- a/mysql-test/main/ctype_latin1.result
+++ b/mysql-test/main/ctype_latin1.result
@@ -838,7 +838,7 @@ create table t1 as select concat(1|2) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) DEFAULT NULL
+  `c1` varchar(20) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(1&2));
@@ -848,7 +848,7 @@ create table t1 as select concat(1&2) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) DEFAULT NULL
+  `c1` varchar(20) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(bit_count(12)));
@@ -868,7 +868,7 @@ create table t1 as select concat(2<<1) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) DEFAULT NULL
+  `c1` varchar(20) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(2>>1));
@@ -878,7 +878,7 @@ create table t1 as select concat(2>>1) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) DEFAULT NULL
+  `c1` varchar(20) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(~0));
@@ -888,7 +888,7 @@ create table t1 as select concat(~0) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) DEFAULT NULL
+  `c1` varchar(20) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(3^2));
@@ -898,7 +898,7 @@ create table t1 as select concat(3^2) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) DEFAULT NULL
+  `c1` varchar(20) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(abs(-2)));
diff --git a/mysql-test/main/ctype_ucs.result b/mysql-test/main/ctype_ucs.result
index fcc8f27010c..98038ba175d 100644
--- a/mysql-test/main/ctype_ucs.result
+++ b/mysql-test/main/ctype_ucs.result
@@ -1717,7 +1717,7 @@ create table t1 as select concat(1|2) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET ucs2 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET ucs2 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(1&2));
@@ -1727,7 +1727,7 @@ create table t1 as select concat(1&2) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET ucs2 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET ucs2 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(bit_count(12)));
@@ -1747,7 +1747,7 @@ create table t1 as select concat(2<<1) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET ucs2 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET ucs2 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(2>>1));
@@ -1757,7 +1757,7 @@ create table t1 as select concat(2>>1) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET ucs2 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET ucs2 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(~0));
@@ -1767,7 +1767,7 @@ create table t1 as select concat(~0) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET ucs2 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET ucs2 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(3^2));
@@ -1777,7 +1777,7 @@ create table t1 as select concat(3^2) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET ucs2 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET ucs2 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(abs(-2)));
diff --git a/mysql-test/main/ctype_utf8.result b/mysql-test/main/ctype_utf8.result
index 10d0efeff3c..8f31e7b04be 100644
--- a/mysql-test/main/ctype_utf8.result
+++ b/mysql-test/main/ctype_utf8.result
@@ -2589,7 +2589,7 @@ create table t1 as select concat(1|2) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET utf8 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET utf8 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(1&2));
@@ -2599,7 +2599,7 @@ create table t1 as select concat(1&2) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET utf8 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET utf8 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(bit_count(12)));
@@ -2619,7 +2619,7 @@ create table t1 as select concat(2<<1) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET utf8 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET utf8 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(2>>1));
@@ -2629,7 +2629,7 @@ create table t1 as select concat(2>>1) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET utf8 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET utf8 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(~0));
@@ -2639,7 +2639,7 @@ create table t1 as select concat(~0) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET utf8 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET utf8 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(3^2));
@@ -2649,7 +2649,7 @@ create table t1 as select concat(3^2) as c1;
 show create table t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `c1` varchar(21) CHARACTER SET utf8 DEFAULT NULL
+  `c1` varchar(20) CHARACTER SET utf8 DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1;
 select hex(concat(abs(-2)));
diff --git a/mysql-test/main/metadata.result b/mysql-test/main/metadata.result
index 7848390b62e..df71496f823 100644
--- a/mysql-test/main/metadata.result
+++ b/mysql-test/main/metadata.result
@@ -512,12 +512,12 @@ BIT_LENGTH(10)
 16
 SELECT 1|2, 1&2, 1<<2, 1>>2, ~0, 1^2;
 Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
-def					1|2	8	21	1	N	32929	0	63
-def					1&2	8	21	1	N	32929	0	63
-def					1<<2	8	21	1	N	32929	0	63
-def					1>>2	8	21	1	N	32929	0	63
-def					~0	8	21	20	N	32929	0	63
-def					1^2	8	21	1	N	32929	0	63
+def					1|2	8	20	1	N	32929	0	63
+def					1&2	8	20	1	N	32929	0	63
+def					1<<2	8	20	1	N	32929	0	63
+def					1>>2	8	20	1	N	32929	0	63
+def					~0	8	20	20	N	32929	0	63
+def					1^2	8	20	1	N	32929	0	63
 1|2	1&2	1<<2	1>>2	~0	1^2
 3	0	4	0	18446744073709551615	3
 SELECT LAST_INSERT_ID();
diff --git a/mysql-test/main/union.result b/mysql-test/main/union.result
index 4e5f9312e03..62674f3b217 100644
--- a/mysql-test/main/union.result
+++ b/mysql-test/main/union.result
@@ -2500,5 +2500,507 @@ t2	CREATE TABLE `t2` (
 DROP TABLE t2;
 DROP TABLE t1;
 #
+# MDEV-13232: Assertion `(&(&share->intern_lock)->m_mutex)->count > 0
+# && pthread_equal(pthread_self(), (&(&share->intern_lock)->m_mutex)->
+# thread)' failed in _ma_state_info_write
+#
+CREATE TABLE t1 (c1 CHAR(1));
+CREATE TABLE t2 (c2 CHAR, d2 decimal(30,10), i2 bigint);
+SET @a= CAST('10' AS CHAR);
+CREATE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT - @a FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(53) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+CREATE OR REPLACE TABLE t3 AS SELECT d2 FROM t2 UNION SELECT - @a FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `d2` double DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+CREATE OR REPLACE TABLE t3 AS SELECT i2 FROM t2 UNION SELECT - @a FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `i2` double DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT - @a FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					- @a	5	53	0	Y	32896	31	63
+- @a
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT abs(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT abs(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					abs(@a)	5	23	0	Y	32896	31	63
+abs(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a+1 FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT @a+1 FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					@a+1	5	23	0	Y	32896	31	63
+ at a+1
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a-1 FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT @a-1 FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					@a-1	5	23	0	Y	32896	31	63
+ at a-1
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a*1 FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT @a*1 FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					@a*1	5	23	0	Y	32896	31	63
+ at a*1
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a/1 FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT @a/1 FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					@a/1	5	23	0	Y	32896	31	63
+ at a/1
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT 1/@a FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT 1/@a FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					1/@a	5	23	0	Y	32896	31	63
+1/@a
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT mod(@a,25) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT mod(@a,25) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					mod(@a,25)	5	23	0	Y	32896	31	63
+mod(@a,25)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT cast(@a as signed) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(20) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT cast(@a as signed) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					cast(@a as signed)	8	20	0	Y	32896	0	63
+cast(@a as signed)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT cast(@a as unsigned) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(20) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT cast(@a as unsigned) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					cast(@a as unsigned)	8	20	0	Y	32928	0	63
+cast(@a as unsigned)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT cast(@a as double) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(22) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT cast(@a as double) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					cast(@a as double)	5	22	0	Y	32896	31	63
+cast(@a as double)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT cast(@a as decimal) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT cast(@a as decimal) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					cast(@a as decimal)	246	11	0	Y	32896	0	63
+cast(@a as decimal)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a DIV 1 FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(20) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT @a DIV 1 FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					@a DIV 1	8	20	0	Y	32896	0	63
+ at a DIV 1
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT exp(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT exp(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					exp(@a)	5	23	0	Y	32896	31	63
+exp(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT ln(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT ln(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					ln(@a)	5	23	0	Y	32896	31	63
+ln(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT log2(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT log2(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					log2(@a)	5	23	0	Y	32896	31	63
+log2(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT log10(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT log10(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					log10(@a)	5	23	0	Y	32896	31	63
+log10(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT log(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT log(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					log(@a)	5	23	0	Y	32896	31	63
+log(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT sqrt(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT sqrt(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					sqrt(@a)	5	23	0	Y	32896	31	63
+sqrt(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT pow(@a,3.5) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT pow(@a,3.5) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					pow(@a,3.5)	5	23	0	Y	32896	31	63
+pow(@a,3.5)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT acos(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT acos(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					acos(@a)	5	23	0	Y	32896	31	63
+acos(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT asin(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT asin(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					asin(@a)	5	23	0	Y	32896	31	63
+asin(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT atan(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT atan(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					atan(@a)	5	23	0	Y	32896	31	63
+atan(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT cos(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT cos(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					cos(@a)	5	23	0	Y	32896	31	63
+cos(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT sin(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT sin(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					sin(@a)	5	23	0	Y	32896	31	63
+sin(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT tan(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT tan(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					tan(@a)	5	23	0	Y	32896	31	63
+tan(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT cot(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT cot(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					cot(@a)	5	23	0	Y	32896	31	63
+cot(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT ceiling(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(17) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT ceiling(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					ceiling(@a)	5	17	0	Y	32896	0	63
+ceiling(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT floor(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(17) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT floor(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					floor(@a)	5	17	0	Y	32896	0	63
+floor(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT round(@a,2) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(19) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT round(@a,2) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					round(@a,2)	5	19	0	Y	32896	2	63
+round(@a,2)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT rand(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT rand(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					rand(@a)	5	23	0	Y	32896	31	63
+rand(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT sign(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(2) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT sign(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					sign(@a)	3	2	0	Y	32896	0	63
+sign(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT degrees(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT degrees(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					degrees(@a)	5	23	0	Y	32896	31	63
+degrees(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT least(@a,2) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT least(@a,2) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					least(@a,2)	5	23	0	Y	32896	31	63
+least(@a,2)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT greatest(@a,2) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(23) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT greatest(@a,2) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					greatest(@a,2)	5	23	0	Y	32896	31	63
+greatest(@a,2)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT octet_length(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(10) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT octet_length(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					octet_length(@a)	3	10	0	Y	32896	0	63
+octet_length(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT bit_length(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT bit_length(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					bit_length(@a)	8	11	0	Y	32896	0	63
+bit_length(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT char_length(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(10) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT char_length(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					char_length(@a)	3	10	0	Y	32896	0	63
+char_length(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT coercibility(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(10) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT coercibility(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					coercibility(@a)	3	10	0	N	32897	0	63
+coercibility(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT ord(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(7) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT ord(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					ord(@a)	3	7	0	Y	32896	0	63
+ord(@a)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT find_in_set(@a,2) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(3) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT find_in_set(@a,2) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					find_in_set(@a,2)	3	3	0	Y	32896	0	63
+find_in_set(@a,2)
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a|1 FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(20) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT @a|1 FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					@a|1	8	20	0	Y	32928	0	63
+ at a|1
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a&1 FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(20) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT @a&1 FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					@a&1	8	20	0	Y	32928	0	63
+ at a&1
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a^1 FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(20) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT @a^1 FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					@a^1	8	20	0	Y	32928	0	63
+ at a^1
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a>>1 FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(20) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT @a>>1 FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					@a>>1	8	20	0	Y	32928	0	63
+ at a>>1
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a<<1 FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(20) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT @a<<1 FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					@a<<1	8	20	0	Y	32928	0	63
+ at a<<1
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT ~@a FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(20) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT ~@a FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					~@a	8	20	0	Y	32928	0	63
+~@a
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT bit_count(@a) FROM t2;
+show create table t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `c1` char(2) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT bit_count(@a) FROM t2;
+Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
+def					bit_count(@a)	3	2	0	Y	32896	0	63
+bit_count(@a)
+drop table t2,t1;
+drop table t3;
+#
 # End of 10.3 tests
 #
diff --git a/mysql-test/main/union.test b/mysql-test/main/union.test
index f86cae87524..532b6c02f6d 100644
--- a/mysql-test/main/union.test
+++ b/mysql-test/main/union.test
@@ -1746,6 +1746,266 @@ DROP TABLE t2;
 DROP TABLE t1;
 
 
+--echo #
+--echo # MDEV-13232: Assertion `(&(&share->intern_lock)->m_mutex)->count > 0
+--echo # && pthread_equal(pthread_self(), (&(&share->intern_lock)->m_mutex)->
+--echo # thread)' failed in _ma_state_info_write
+--echo #
+
+CREATE TABLE t1 (c1 CHAR(1));
+ 
+CREATE TABLE t2 (c2 CHAR, d2 decimal(30,10), i2 bigint);
+SET @a= CAST('10' AS CHAR);
+ 
+CREATE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT - @a FROM t2;
+show create table t3;
+CREATE OR REPLACE TABLE t3 AS SELECT d2 FROM t2 UNION SELECT - @a FROM t2;
+show create table t3;
+CREATE OR REPLACE TABLE t3 AS SELECT i2 FROM t2 UNION SELECT - @a FROM t2;
+show create table t3;
+--enable_metadata
+SELECT - @a FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT abs(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT abs(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a+1 FROM t2;
+show create table t3;
+--enable_metadata
+SELECT @a+1 FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a-1 FROM t2;
+show create table t3;
+--enable_metadata
+SELECT @a-1 FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a*1 FROM t2;
+show create table t3;
+--enable_metadata
+SELECT @a*1 FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a/1 FROM t2;
+show create table t3;
+--enable_metadata
+SELECT @a/1 FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT 1/@a FROM t2;
+show create table t3;
+--enable_metadata
+SELECT 1/@a FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT mod(@a,25) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT mod(@a,25) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT cast(@a as signed) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT cast(@a as signed) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT cast(@a as unsigned) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT cast(@a as unsigned) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT cast(@a as double) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT cast(@a as double) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT cast(@a as decimal) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT cast(@a as decimal) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a DIV 1 FROM t2;
+show create table t3;
+--enable_metadata
+SELECT @a DIV 1 FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT exp(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT exp(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT ln(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT ln(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT log2(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT log2(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT log10(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT log10(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT log(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT log(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT sqrt(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT sqrt(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT pow(@a,3.5) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT pow(@a,3.5) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT acos(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT acos(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT asin(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT asin(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT atan(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT atan(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT cos(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT cos(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT sin(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT sin(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT tan(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT tan(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT cot(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT cot(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT ceiling(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT ceiling(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT floor(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT floor(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT round(@a,2) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT round(@a,2) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT rand(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT rand(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT sign(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT sign(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT degrees(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT degrees(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT least(@a,2) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT least(@a,2) FROM t2;
+--disable_metadata
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT greatest(@a,2) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT greatest(@a,2) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT octet_length(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT octet_length(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT bit_length(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT bit_length(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT char_length(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT char_length(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT coercibility(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT coercibility(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT ord(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT ord(@a) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT find_in_set(@a,2) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT find_in_set(@a,2) FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a|1 FROM t2;
+show create table t3;
+--enable_metadata
+SELECT @a|1 FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a&1 FROM t2;
+show create table t3;
+--enable_metadata
+SELECT @a&1 FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a^1 FROM t2;
+show create table t3;
+--enable_metadata
+SELECT @a^1 FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a>>1 FROM t2;
+show create table t3;
+--enable_metadata
+SELECT @a>>1 FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT @a<<1 FROM t2;
+show create table t3;
+--enable_metadata
+SELECT @a<<1 FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT ~@a FROM t2;
+show create table t3;
+--enable_metadata
+SELECT ~@a FROM t2;
+--disable_metadata
+CREATE OR REPLACE TABLE t3 AS SELECT c1 FROM t1 UNION SELECT bit_count(@a) FROM t2;
+show create table t3;
+--enable_metadata
+SELECT bit_count(@a) FROM t2;
+--disable_metadata
+
+drop table t2,t1;
+drop table t3;
+
 --echo #
 --echo # End of 10.3 tests
 --echo #
diff --git a/mysql-test/suite/rpl/r/rpl_row_create_select.result b/mysql-test/suite/rpl/r/rpl_row_create_select.result
index b064d42982f..694b0c2e342 100644
--- a/mysql-test/suite/rpl/r/rpl_row_create_select.result
+++ b/mysql-test/suite/rpl/r/rpl_row_create_select.result
@@ -14,7 +14,7 @@ Warning	1292	Truncated incorrect DECIMAL value: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
 SHOW CREATE TABLE t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
-  `a` bigint(21) DEFAULT NULL
+  `a` bigint(20) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
 CREATE TABLE t2 AS SELECT CONVERT(REPEAT('A', 255) USING UCS2) DIV 1 AS a;
@@ -23,7 +23,7 @@ Warning	1292	Truncated incorrect DECIMAL value: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
 SHOW CREATE TABLE t2;
 Table	Create Table
 t2	CREATE TABLE `t2` (
-  `a` bigint(21) DEFAULT NULL
+  `a` bigint(20) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 #After the patch, no error is reported.
 connection slave;
diff --git a/sql/item.h b/sql/item.h
index 9574bdc63bf..81d2a198495 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -2023,6 +2023,11 @@ class Item: public Value_source,
   {
     marker &= ~EXTRACTION_MASK;
   }
+  void fix_length_according_to_type_handler()
+  {
+    uint32 mlen= type_handler()->max_display_length(this);
+    set_if_smaller(max_length, mlen);
+  }
 };
 
 MEM_ROOT *get_thd_memroot(THD *thd);
diff --git a/sql/item_func.cc b/sql/item_func.cc
index e2740272385..8b09040ccf5 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -802,6 +802,7 @@ void Item_func_plus::fix_length_and_dec(void)
     Item_func_plus::type_handler()->Item_func_plus_fix_length_and_dec(this);
     DBUG_PRINT("info", ("Type: %s", type_handler()->name().ptr()));
   }
+  DBUG_ASSERT(max_length <= type_handler()->max_display_length(this));
   DBUG_VOID_RETURN;
 }
 
@@ -1328,6 +1329,7 @@ void Item_func_minus::fix_length_and_dec()
     Item_func_minus::type_handler()->Item_func_minus_fix_length_and_dec(this);
     DBUG_PRINT("info", ("Type: %s", type_handler()->name().ptr()));
   }
+  fix_length_according_to_type_handler();
   DBUG_VOID_RETURN;
 }
 
@@ -1560,6 +1562,7 @@ void Item_func_mul::fix_length_and_dec(void)
     Item_func_mul::type_handler()->Item_func_mul_fix_length_and_dec(this);
     DBUG_PRINT("info", ("Type: %s", type_handler()->name().ptr()));
   }
+  DBUG_ASSERT(max_length <= type_handler()->max_display_length(this));
   DBUG_VOID_RETURN;
 }
 
@@ -1670,6 +1673,7 @@ void Item_func_div::fix_length_and_dec(void)
     Item_func_div::type_handler()->Item_func_div_fix_length_and_dec(this);
     DBUG_PRINT("info", ("Type: %s", type_handler()->name().ptr()));
   }
+  DBUG_ASSERT(max_length <= type_handler()->max_display_length(this));
   DBUG_VOID_RETURN;
 }
 
@@ -1757,6 +1761,7 @@ void Item_func_int_div::fix_length_and_dec()
                   MY_INT64_NUM_DECIMAL_DIGITS : char_length);
   maybe_null=1;
   unsigned_flag=args[0]->unsigned_flag | args[1]->unsigned_flag;
+  fix_length_according_to_type_handler();
 }
 
 
@@ -1854,6 +1859,7 @@ void Item_func_mod::fix_length_and_dec()
     DBUG_PRINT("info", ("Type: %s", type_handler()->name().ptr()));
   }
   DBUG_VOID_RETURN;
+  DBUG_ASSERT(max_length <= type_handler()->max_display_length(this));
 }
 
 
@@ -1954,6 +1960,9 @@ void Item_func_neg::fix_length_and_dec()
   DBUG_PRINT("info", ("name %s", func_name()));
   args[0]->cast_to_int_type_handler()->Item_func_neg_fix_length_and_dec(this);
   DBUG_PRINT("info", ("Type: %s", type_handler()->name().ptr()));
+
+  // limit length with some realistic figures for double
+  fix_length_according_to_type_handler();
   DBUG_VOID_RETURN;
 }
 
@@ -2026,6 +2035,7 @@ void Item_func_abs::fix_length_and_dec()
   DBUG_PRINT("info", ("name %s", func_name()));
   args[0]->cast_to_int_type_handler()->Item_func_abs_fix_length_and_dec(this);
   DBUG_PRINT("info", ("Type: %s", type_handler()->name().ptr()));
+  fix_length_according_to_type_handler();
   DBUG_VOID_RETURN;
 }
 
@@ -2299,6 +2309,7 @@ void Item_func_int_val::fix_length_and_dec()
   args[0]->cast_to_int_type_handler()->
     Item_func_int_val_fix_length_and_dec(this);
   DBUG_PRINT("info", ("Type: %s", type_handler()->name().ptr()));
+  DBUG_ASSERT(max_length <= type_handler()->max_display_length(this));
   DBUG_VOID_RETURN;
 }
 
@@ -3044,6 +3055,7 @@ void Item_func_field::fix_length_and_dec()
     cmp_type= item_cmp_type(cmp_type, args[i]->result_type());
   if (cmp_type == STRING_RESULT)
     agg_arg_charsets_for_comparison(cmp_collation, args, arg_count);
+  DBUG_ASSERT(max_length <= type_handler()->max_display_length(this));
 }
 
 
@@ -3113,6 +3125,7 @@ void Item_func_find_in_set::fix_length_and_dec()
     }
   }
   agg_arg_charsets_for_comparison(cmp_collation, args, 2);
+  DBUG_ASSERT(max_length <= type_handler()->max_display_length(this));
 }
 
 static const char separator=',';
diff --git a/sql/item_func.h b/sql/item_func.h
index 74e469ea9f3..ce1e7a3959c 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -734,6 +734,7 @@ class Item_num_op :public Item_func_numhybrid
     result_precision();
     decimals= 0;
     set_handler(type_handler_long_or_longlong());
+    fix_length_according_to_type_handler();
   }
   void fix_length_and_dec_temporal()
   {
@@ -911,6 +912,7 @@ class Item_func_signed :public Item_int_func
   void fix_length_and_dec()
   {
     args[0]->type_handler()->Item_func_signed_fix_length_and_dec(this);
+    fix_length_according_to_type_handler();
   }
   virtual void print(String *str, enum_query_type query_type);
   uint decimal_precision() const { return args[0]->decimal_precision(); }
@@ -943,6 +945,7 @@ class Item_func_unsigned :public Item_func_signed
   void fix_length_and_dec()
   {
     args[0]->type_handler()->Item_func_unsigned_fix_length_and_dec(this);
+    fix_length_according_to_type_handler();
   }
   uint decimal_precision() const { return max_length; }
   virtual void print(String *str, enum_query_type query_type);
@@ -974,6 +977,7 @@ class Item_decimal_typecast :public Item_func
   void fix_length_and_dec()
   {
     args[0]->type_handler()->Item_decimal_typecast_fix_length_and_dec(this);
+    DBUG_ASSERT(max_length <= type_handler()->max_display_length(this));
   }
   const char *func_name() const { return "decimal_typecast"; }
   virtual void print(String *str, enum_query_type query_type);
@@ -1803,7 +1807,11 @@ class Item_func_bit: public Item_longlong_func
 public:
   Item_func_bit(THD *thd, Item *a, Item *b): Item_longlong_func(thd, a, b) {}
   Item_func_bit(THD *thd, Item *a): Item_longlong_func(thd, a) {}
-  void fix_length_and_dec() { unsigned_flag= 1; }
+  void fix_length_and_dec()
+  {
+    unsigned_flag= 1;
+    fix_length_according_to_type_handler();
+  }
 
   virtual inline void print(String *str, enum_query_type query_type)
   {


More information about the commits mailing list