Commit 5dcc56be authored by Alexander Barkov's avatar Alexander Barkov

MDEV-29561 SHOW CREATE TABLE produces syntactically incorrect structure

parent 65b4a2af
...@@ -21,7 +21,7 @@ t1 CREATE TABLE `t1` ( ...@@ -21,7 +21,7 @@ t1 CREATE TABLE `t1` (
`c7` binary(1) DEFAULT NULL, `c7` binary(1) DEFAULT NULL,
`c8` varbinary(10) DEFAULT NULL, `c8` varbinary(10) DEFAULT NULL,
`c9` geometry DEFAULT NULL `c9` geometry DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=binary COLLATE=binary ) ENGINE=MyISAM DEFAULT CHARSET=binary
INSERT INTO t1 VALUES ('tinyblob-text readable', 'blob-text readable', INSERT INTO t1 VALUES ('tinyblob-text readable', 'blob-text readable',
'mediumblob-text readable', 'longblob-text readable', 'mediumblob-text readable', 'longblob-text readable',
'text readable', b'1', 'c', 'variable', 'text readable', b'1', 'c', 'variable',
......
...@@ -3178,7 +3178,7 @@ CREATE TABLE t1(a ENUM(0x6100,0x6200,0x6300) CHARACTER SET 'Binary'); ...@@ -3178,7 +3178,7 @@ CREATE TABLE t1(a ENUM(0x6100,0x6200,0x6300) CHARACTER SET 'Binary');
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`a` enum('a\0','b\0','c\0') CHARACTER SET binary COLLATE binary DEFAULT NULL `a` enum('a\0','b\0','c\0') CHARACTER SET binary DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
INSERT INTO t1 VALUES (1),(2),(3); INSERT INTO t1 VALUES (1),(2),(3);
SELECT HEX(a) FROM t1 ORDER BY a; SELECT HEX(a) FROM t1 ORDER BY a;
...@@ -3279,7 +3279,7 @@ CREATE TABLE t1(c ENUM(0x0061) CHARACTER SET 'Binary', d JSON); ...@@ -3279,7 +3279,7 @@ CREATE TABLE t1(c ENUM(0x0061) CHARACTER SET 'Binary', d JSON);
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`c` enum('\0a') CHARACTER SET binary COLLATE binary DEFAULT NULL, `c` enum('\0a') CHARACTER SET binary DEFAULT NULL,
`d` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL `d` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
INSERT INTO t1 (c) VALUES (1); INSERT INTO t1 (c) VALUES (1);
...@@ -3294,7 +3294,7 @@ d INT DEFAULT NULL CHECK (d>0) ...@@ -3294,7 +3294,7 @@ d INT DEFAULT NULL CHECK (d>0)
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`c` enum('\0a') CHARACTER SET binary COLLATE binary DEFAULT NULL, `c` enum('\0a') CHARACTER SET binary DEFAULT NULL,
`d` int(11) DEFAULT NULL CHECK (`d` > 0) `d` int(11) DEFAULT NULL CHECK (`d` > 0)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
INSERT INTO t1 VALUES (1,1); INSERT INTO t1 VALUES (1,1);
...@@ -3306,7 +3306,7 @@ CREATE TABLE t1(c ENUM(0x0061) CHARACTER SET 'Binary' CHECK (c>0)); ...@@ -3306,7 +3306,7 @@ CREATE TABLE t1(c ENUM(0x0061) CHARACTER SET 'Binary' CHECK (c>0));
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`c` enum('\0a') CHARACTER SET binary COLLATE binary DEFAULT NULL CHECK (`c` > 0) `c` enum('\0a') CHARACTER SET binary DEFAULT NULL CHECK (`c` > 0)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
INSERT INTO t1 VALUES (1); INSERT INTO t1 VALUES (1);
SELECT HEX(c) FROM t1; SELECT HEX(c) FROM t1;
...@@ -3316,3 +3316,47 @@ DROP TABLE t1; ...@@ -3316,3 +3316,47 @@ DROP TABLE t1;
# #
# End of 10.2 tests # End of 10.2 tests
# #
#
# Start of 10.3 tests
#
#
# MDEV-29561 SHOW CREATE TABLE produces syntactically incorrect structure
#
CREATE TABLE t1 (a ENUM('x') CHARACTER SET BINARY);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` enum('x') CHARACTER SET binary DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
DROP TABLE t1;
CREATE TABLE `t1` (
`a` enum('x') CHARACTER SET binary DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;
DROP TABLE t1;
CREATE TABLE t1 (a INT ) CHARSET=binary;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=binary
DROP TABLE t1;
CREATE DATABASE db1 CHARACTER SET BINARY;
SHOW CREATE DATABASE db1;
Database Create Database
db1 CREATE DATABASE `db1` /*!40100 DEFAULT CHARACTER SET binary */
DROP DATABASE db1;
CREATE FUNCTION f1() RETURNS ENUM('a') CHARACTER SET binary RETURN NULL;
SHOW CREATE FUNCTION f1;
Function sql_mode Create Function character_set_client collation_connection Database Collation
f1 STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS enum('a') CHARSET binary
RETURN NULL latin1 latin1_swedish_ci latin1_swedish_ci
DROP FUNCTION f1;
CREATE FUNCTION f1(a ENUM('a') CHARACTER SET binary) RETURNS INT RETURN NULL;
SHOW CREATE FUNCTION f1;
Function sql_mode Create Function character_set_client collation_connection Database Collation
f1 STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` FUNCTION `f1`(a ENUM('a') CHARACTER SET binary) RETURNS int(11)
RETURN NULL latin1 latin1_swedish_ci latin1_swedish_ci
DROP FUNCTION f1;
#
# End of 10.3 tests
#
...@@ -169,12 +169,42 @@ INSERT INTO t1 VALUES (1); ...@@ -169,12 +169,42 @@ INSERT INTO t1 VALUES (1);
SELECT HEX(c) FROM t1; SELECT HEX(c) FROM t1;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # End of 10.2 tests
--echo #
--echo #
--echo # Start of 10.3 tests
--echo #
--echo #
--echo # MDEV-29561 SHOW CREATE TABLE produces syntactically incorrect structure
--echo #
CREATE TABLE t1 (a ENUM('x') CHARACTER SET BINARY);
SHOW CREATE TABLE t1;
let $def= query_get_value(show create table t1,'Create Table',1);
DROP TABLE t1;
eval $def;
DROP TABLE t1;
CREATE TABLE t1 (a INT ) CHARSET=binary;
SHOW CREATE TABLE t1;
DROP TABLE t1;
CREATE DATABASE db1 CHARACTER SET BINARY;
SHOW CREATE DATABASE db1;
DROP DATABASE db1;
CREATE FUNCTION f1() RETURNS ENUM('a') CHARACTER SET binary RETURN NULL;
SHOW CREATE FUNCTION f1;
DROP FUNCTION f1;
CREATE FUNCTION f1(a ENUM('a') CHARACTER SET binary) RETURNS INT RETURN NULL;
SHOW CREATE FUNCTION f1;
DROP FUNCTION f1;
--echo # --echo #
--echo # End of 10.2 tests --echo # End of 10.3 tests
--echo # --echo #
...@@ -7907,7 +7907,7 @@ CREATE TABLE t1(c ENUM('aaaaaaaa') CHARACTER SET 'Binary',d JSON); ...@@ -7907,7 +7907,7 @@ CREATE TABLE t1(c ENUM('aaaaaaaa') CHARACTER SET 'Binary',d JSON);
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`c` enum('\0a\0a\0a\0a\0a\0a\0a\0a') CHARACTER SET binary COLLATE binary DEFAULT NULL, `c` enum('\0a\0a\0a\0a\0a\0a\0a\0a') CHARACTER SET binary DEFAULT NULL,
`d` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL `d` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
INSERT INTO t1 (c) VALUES (1); INSERT INTO t1 (c) VALUES (1);
...@@ -7919,7 +7919,7 @@ CREATE OR REPLACE TABLE t1(c ENUM('aaaaaaaaa') CHARACTER SET 'Binary',d JSON); ...@@ -7919,7 +7919,7 @@ CREATE OR REPLACE TABLE t1(c ENUM('aaaaaaaaa') CHARACTER SET 'Binary',d JSON);
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`c` enum('\0a\0a\0a\0a\0a\0a\0a\0a\0a') CHARACTER SET binary COLLATE binary DEFAULT NULL, `c` enum('\0a\0a\0a\0a\0a\0a\0a\0a\0a') CHARACTER SET binary DEFAULT NULL,
`d` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL `d` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
INSERT INTO t1 (c) VALUES (1); INSERT INTO t1 (c) VALUES (1);
...@@ -7931,7 +7931,7 @@ CREATE OR REPLACE TABLE t1(c ENUM('aaaaaaaaaa') CHARACTER SET 'Binary',d JSON); ...@@ -7931,7 +7931,7 @@ CREATE OR REPLACE TABLE t1(c ENUM('aaaaaaaaaa') CHARACTER SET 'Binary',d JSON);
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`c` enum('\0a\0a\0a\0a\0a\0a\0a\0a\0a\0a') CHARACTER SET binary COLLATE binary DEFAULT NULL, `c` enum('\0a\0a\0a\0a\0a\0a\0a\0a\0a\0a') CHARACTER SET binary DEFAULT NULL,
`d` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL `d` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
INSERT INTO t1 (c) VALUES (1); INSERT INTO t1 (c) VALUES (1);
......
...@@ -2878,7 +2878,7 @@ CREATE TABLE t1(c1 ENUM('a','b','ac') CHARACTER SET 'Binary',c2 JSON,c3 INT); ...@@ -2878,7 +2878,7 @@ CREATE TABLE t1(c1 ENUM('a','b','ac') CHARACTER SET 'Binary',c2 JSON,c3 INT);
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`c1` enum('\0\0\0a','\0\0\0b','\0\0\0a\0\0\0c') CHARACTER SET binary COLLATE binary DEFAULT NULL, `c1` enum('\0\0\0a','\0\0\0b','\0\0\0a\0\0\0c') CHARACTER SET binary DEFAULT NULL,
`c2` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, `c2` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
`c3` int(11) DEFAULT NULL `c3` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
......
...@@ -1052,8 +1052,11 @@ sp_returns_type(THD *thd, String &result, const sp_head *sp) ...@@ -1052,8 +1052,11 @@ sp_returns_type(THD *thd, String &result, const sp_head *sp)
{ {
result.append(STRING_WITH_LEN(" CHARSET ")); result.append(STRING_WITH_LEN(" CHARSET "));
result.append(field->charset()->csname); result.append(field->charset()->csname);
result.append(STRING_WITH_LEN(" COLLATE ")); if (Charset(field->charset()).can_have_collate_clause())
result.append(field->charset()->name); {
result.append(STRING_WITH_LEN(" COLLATE "));
result.append(field->charset()->name);
}
} }
delete field; delete field;
......
...@@ -1551,8 +1551,11 @@ bool mysqld_show_create_db(THD *thd, LEX_CSTRING *dbname, ...@@ -1551,8 +1551,11 @@ bool mysqld_show_create_db(THD *thd, LEX_CSTRING *dbname,
buffer.append(STRING_WITH_LEN(" /*!40100")); buffer.append(STRING_WITH_LEN(" /*!40100"));
buffer.append(STRING_WITH_LEN(" DEFAULT CHARACTER SET ")); buffer.append(STRING_WITH_LEN(" DEFAULT CHARACTER SET "));
buffer.append(create.default_table_charset->csname); buffer.append(create.default_table_charset->csname);
buffer.append(STRING_WITH_LEN(" COLLATE ")); if (Charset(create.default_table_charset).can_have_collate_clause())
buffer.append(create.default_table_charset->name); {
buffer.append(STRING_WITH_LEN(" COLLATE "));
buffer.append(create.default_table_charset->name);
}
buffer.append(STRING_WITH_LEN(" */")); buffer.append(STRING_WITH_LEN(" */"));
} }
protocol->store(buffer.ptr(), buffer.length(), buffer.charset()); protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
...@@ -2010,8 +2013,11 @@ static void add_table_options(THD *thd, TABLE *table, ...@@ -2010,8 +2013,11 @@ static void add_table_options(THD *thd, TABLE *table,
{ {
packet->append(STRING_WITH_LEN(" DEFAULT CHARSET=")); packet->append(STRING_WITH_LEN(" DEFAULT CHARSET="));
packet->append(share->table_charset->csname); packet->append(share->table_charset->csname);
packet->append(STRING_WITH_LEN(" COLLATE=")); if (Charset(table->s->table_charset).can_have_collate_clause())
packet->append(table->s->table_charset->name); {
packet->append(STRING_WITH_LEN(" COLLATE="));
packet->append(table->s->table_charset->name);
}
} }
} }
...@@ -2245,10 +2251,13 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, ...@@ -2245,10 +2251,13 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
{ {
if (field->charset() != share->table_charset) if (field->charset() != share->table_charset)
{ {
packet->append(STRING_WITH_LEN(" CHARACTER SET ")); packet->append(STRING_WITH_LEN(" CHARACTER SET "));
packet->append(field->charset()->csname); packet->append(field->charset()->csname);
packet->append(STRING_WITH_LEN(" COLLATE ")); if (Charset(field->charset()).can_have_collate_clause())
packet->append(field->charset()->name); {
packet->append(STRING_WITH_LEN(" COLLATE "));
packet->append(field->charset()->name);
}
} }
} }
......
...@@ -147,6 +147,10 @@ class Charset ...@@ -147,6 +147,10 @@ class Charset
LEX_CSTRING collation_specific_name() const; LEX_CSTRING collation_specific_name() const;
bool encoding_allows_reinterpret_as(CHARSET_INFO *cs) const; bool encoding_allows_reinterpret_as(CHARSET_INFO *cs) const;
bool eq_collation_specific_names(CHARSET_INFO *cs) const; bool eq_collation_specific_names(CHARSET_INFO *cs) const;
bool can_have_collate_clause() const
{
return m_charset != &my_charset_bin;
}
}; };
class String : public Sql_alloc class String : public Sql_alloc
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment