From c4843c10a3f774095cfe8bf8ac661858d48be9a1 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 14 Nov 2024 17:05:31 +0400 Subject: [PATCH] MDEV-35416 CONV(1<<63, 10, -2) fails with --view-protocol Item_func_conv::fix_length_and_dec() incorrectly set maximum length as 64 character. But for negative numbers it can return up to 65 charcters (including the sign). --- mysql-test/main/func_str.result | 18 ++++++++++++++---- mysql-test/main/func_str.test | 8 ++++++++ sql/item_strfunc.h | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/mysql-test/main/func_str.result b/mysql-test/main/func_str.result index 90c8de420f2..b8aac9cda06 100644 --- a/mysql-test/main/func_str.result +++ b/mysql-test/main/func_str.result @@ -745,9 +745,9 @@ encode('abcd','ab') show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `bin(130)` varchar(64) DEFAULT NULL, - `oct(130)` varchar(64) DEFAULT NULL, - `conv(130,16,10)` varchar(64) DEFAULT NULL, + `bin(130)` varchar(65) DEFAULT NULL, + `oct(130)` varchar(65) DEFAULT NULL, + `conv(130,16,10)` varchar(65) DEFAULT NULL, `hex(130)` varchar(16) DEFAULT NULL, `char(130)` varbinary(4) DEFAULT NULL, `format(130,10)` varchar(25) DEFAULT NULL, @@ -5260,7 +5260,7 @@ conv(i,16,2) SHOW CREATE TABLE t2; Table Create Table t2 CREATE TABLE `t2` ( - `conv(i,16,2)` varchar(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL + `conv(i,16,2)` varchar(65) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci DROP TABLE t1,t2; # @@ -5397,5 +5397,15 @@ SELECT CONV(1<<63, 10, -2); CONV(1<<63, 10, -2) -1000000000000000000000000000000000000000000000000000000000000000 # +# MDEV-35416 CONV(1<<63, 10, -2) fails with --view-protocol +# +CREATE TABLE t1 AS SELECT CONV(1<<63, 10, -2) AS c1; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` varchar(65) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +# # End of 10.6 tests # diff --git a/mysql-test/main/func_str.test b/mysql-test/main/func_str.test index 8fe2892b1e3..518e9dcc049 100644 --- a/mysql-test/main/func_str.test +++ b/mysql-test/main/func_str.test @@ -2439,6 +2439,14 @@ DROP TABLE t0; SELECT CONV(-29223372036854775809, -10, 18446744073709551614); SELECT CONV(1<<63, 10, -2); +--echo # +--echo # MDEV-35416 CONV(1<<63, 10, -2) fails with --view-protocol +--echo # + +CREATE TABLE t1 AS SELECT CONV(1<<63, 10, -2) AS c1; +SHOW CREATE TABLE t1; +DROP TABLE t1; + --echo # --echo # End of 10.6 tests --echo # diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 995f07ed0d0..3da743531b9 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -1547,7 +1547,7 @@ public: bool fix_length_and_dec() override { collation.set(default_charset()); - fix_char_length(64); + fix_char_length(65); set_maybe_null(); return FALSE; }