Skip to content

Commit 29bb321

Browse files
committed
MDEV-33788 HEX(COLUMN_CREATE(.. AS CHAR ...)) fails with --view-protocol
Item_func_dyncol_create::print_arguments() printed only CHARSET clause without COLLATE. Therefore, HEX(column_create(1,'1212' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_bin)) inside a VIEW changed to just: HEX(column_create(1,'1212' AS CHAR CHARACTER SET utf8mb3)) which changed the collation ID seen in the HEX output. Note, the collation ID inside column_create() is not really much important. (It's only important what the character set is). And for COLLATE, the more important thing is what's later written in the AS clause of COLUMN_GET: SELECT COLUMN_GET( column_create(1,'1212' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_bin) column_nr AS type -- this type is more important ); Still, let's add the COLLATE clause into the COLUMN_CREATE() print output, although it's not important for now for anything else than just the HEX output. At least to make VIEW work in a more predictable way with HEX(COLUMN_CREATE()). Also, in the future we can start using somehow the collation ID written inside COLUMN_CREATE(), for example by making the `AS type` clause optional in COLUMN_GET(): COLUMN_GET(dyncol_blob, column_nr [AS type]); instead of: COLUMN_GET(dyncol_blob, column_nr AS type); SQL Server compatibility layer may need this for the SQL_Variant data type support.
1 parent e1876e7 commit 29bb321

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

mysql-test/main/create.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ show create table t1;
18061806
Table Create Table
18071807
t1 CREATE TABLE `t1` (
18081808
`color` char(32) GENERATED ALWAYS AS (column_get(`dynamic_cols`,1 as char charset latin1)) STORED,
1809-
`cl` char(32) GENERATED ALWAYS AS (column_get(column_add(column_create(1,'blue' AS char charset latin1 ),2,'ttt'),`i` as char charset latin1)) STORED,
1809+
`cl` char(32) GENERATED ALWAYS AS (column_get(column_add(column_create(1,'blue' AS char charset latin1 collate latin1_swedish_ci ),2,'ttt'),`i` as char charset latin1)) STORED,
18101810
`item_name` varchar(32) NOT NULL,
18111811
`i` int(11) DEFAULT NULL,
18121812
`dynamic_cols` blob DEFAULT NULL,

mysql-test/main/dyncol.result

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ select hex(COLUMN_CREATE(1, "afaf" AS char character set utf8,
150150
id select_type table type possible_keys key key_len ref rows filtered Extra
151151
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
152152
Warnings:
153-
Note 1003 select hex(column_create(1,'afaf' AS char charset utf8 ,2,1212 AS unsigned int,3,1212 AS int,4,12.12 AS double,4 + 1,12.12 AS decimal,6,'2011-04-05' AS date,7,'- 0:45:49.000001' AS time,8,'2011-04-05 0:45:49.000001' AS datetime)) AS `ex`
153+
Note 1003 select hex(column_create(1,'afaf' AS char charset utf8 collate utf8_general_ci ,2,1212 AS unsigned int,3,1212 AS int,4,12.12 AS double,4 + 1,12.12 AS decimal,6,'2011-04-05' AS date,7,'- 0:45:49.000001' AS time,8,'2011-04-05 0:45:49.000001' AS datetime)) AS `ex`
154154
select hex(column_create(1, 0.0 AS decimal));
155155
hex(column_create(1, 0.0 AS decimal))
156156
000100010004
@@ -354,7 +354,7 @@ select column_get(column_create(1, "1212" AS char charset utf8), 1 as char chars
354354
id select_type table type possible_keys key key_len ref rows filtered Extra
355355
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
356356
Warnings:
357-
Note 1003 select column_get(column_create(1,'1212' AS char charset utf8 ),1 as char charset utf8) AS `ex`
357+
Note 1003 select column_get(column_create(1,'1212' AS char charset utf8 collate utf8_general_ci ),1 as char charset utf8) AS `ex`
358358
select column_get(column_create(1, 1212 AS unsigned int), 1 as char charset utf8) as ex;
359359
ex
360360
1212
@@ -414,7 +414,7 @@ select column_get(column_create(1, "1212" AS char charset utf8), 1 as char chars
414414
id select_type table type possible_keys key key_len ref rows filtered Extra
415415
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
416416
Warnings:
417-
Note 1003 select column_get(column_create(1,'1212' AS char charset utf8 ),1 as char charset binary) AS `ex`
417+
Note 1003 select column_get(column_create(1,'1212' AS char charset utf8 collate utf8_general_ci ),1 as char charset binary) AS `ex`
418418
#
419419
# column get real
420420
#
@@ -1882,7 +1882,7 @@ drop table t1;
18821882
create view v1 as select column_get(column_add(column_create(1 , 'blue' as char), 2, 'ttt'), 1 as char);
18831883
show create view v1;
18841884
View Create View character_set_client collation_connection
1885-
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select column_get(column_add(column_create(1,'blue' AS char charset utf8 ),2,'ttt'),1 as char charset utf8) AS `Name_exp_1` utf8 utf8_general_ci
1885+
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select column_get(column_add(column_create(1,'blue' AS char charset utf8 collate utf8_general_ci ),2,'ttt'),1 as char charset utf8) AS `Name_exp_1` utf8 utf8_general_ci
18861886
select * from v1;
18871887
Name_exp_1
18881888
blue
@@ -1949,3 +1949,23 @@ ex
19491949
#
19501950
# End of 10.4 tests
19511951
#
1952+
#
1953+
# Start of 10.5 tests
1954+
#
1955+
#
1956+
# Start of 10.5 tests
1957+
#
1958+
#
1959+
# MDEV-33788 HEX(COLUMN_CREATE(.. AS CHAR ...)) fails with --view-protocol
1960+
#
1961+
SELECT hex(column_create(1,'a' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_bin)) AS ex;
1962+
ex
1963+
0001000100035361
1964+
SELECT hex(column_add(column_create(
1965+
1, 'a' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_bin),
1966+
2, 'b' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci)) AS ex;
1967+
ex
1968+
00020001000302001353612162
1969+
#
1970+
# Start of 10.5 tests
1971+
#

mysql-test/main/dyncol.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,3 +1000,24 @@ SELECT HEX(COLUMN_ADD(COLUMN_CREATE(1,10),2,NULL,1,NULL)) as ex;
10001000
--echo #
10011001
--echo # End of 10.4 tests
10021002
--echo #
1003+
1004+
--echo #
1005+
--echo # Start of 10.5 tests
1006+
--echo #
1007+
1008+
--echo #
1009+
--echo # Start of 10.5 tests
1010+
--echo #
1011+
1012+
--echo #
1013+
--echo # MDEV-33788 HEX(COLUMN_CREATE(.. AS CHAR ...)) fails with --view-protocol
1014+
--echo #
1015+
1016+
SELECT hex(column_create(1,'a' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_bin)) AS ex;
1017+
SELECT hex(column_add(column_create(
1018+
1, 'a' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_bin),
1019+
2, 'b' AS CHAR CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci)) AS ex;
1020+
1021+
--echo #
1022+
--echo # Start of 10.5 tests
1023+
--echo #

sql/item_strfunc.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4670,6 +4670,11 @@ void Item_func_dyncol_create::print_arguments(String *str,
46704670
{
46714671
str->append(STRING_WITH_LEN(" charset "));
46724672
str->append(defs[i].cs->csname);
4673+
if (Charset(defs[i].cs).can_have_collate_clause())
4674+
{
4675+
str->append(STRING_WITH_LEN(" collate "));
4676+
str->append(defs[i].cs->name);
4677+
}
46734678
str->append(' ');
46744679
}
46754680
break;

0 commit comments

Comments
 (0)