diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2019-06-13 15:36:41 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2019-06-13 15:36:41 +0400 |
commit | 079457985317d2ab9ab63c96d35f47aff948ed08 (patch) | |
tree | 79fcf18322dc5417a2970a8971c5ccd0e8e0eb3b | |
parent | cf78b8c699d8394a52c55b38e67a865d6a44c500 (diff) | |
download | mariadb-git-bb-10.3-svoj-MDEV-17363.tar.gz |
MDEV-17363 - Compressed columns cannot be restored from dumpbb-10.3-svoj-MDEV-17363
Fixed parser so that COMPRESSED after data type becomes valid and
COMPRESSED after column attributes becomes deprecated.
-rw-r--r-- | mysql-test/main/column_compression.result | 48 | ||||
-rw-r--r-- | mysql-test/main/column_compression.test | 27 | ||||
-rw-r--r-- | sql/field.cc | 28 | ||||
-rw-r--r-- | sql/field.h | 1 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 55 | ||||
-rw-r--r-- | sql/sql_yacc_ora.yy | 55 |
6 files changed, 143 insertions, 71 deletions
diff --git a/mysql-test/main/column_compression.result b/mysql-test/main/column_compression.result index c783e7fd1e9..cfc1ad71a02 100644 --- a/mysql-test/main/column_compression.result +++ b/mysql-test/main/column_compression.result @@ -860,9 +860,9 @@ foo bar DROP TABLE t1; FLUSH STATUS; -CREATE TABLE t1(a TEXT CHARSET ucs2 COMPRESSED, KEY(a(10))); +CREATE TABLE t1(a TEXT COMPRESSED CHARSET ucs2, KEY(a(10))); ERROR HY000: Compressed column 'a' can't be used in key specification -CREATE TABLE t1(a TEXT CHARSET ucs2 COMPRESSED); +CREATE TABLE t1(a TEXT COMPRESSED CHARSET ucs2); ALTER TABLE t1 ADD KEY(a(10)); ERROR HY000: Compressed column 'a' can't be used in key specification SHOW CREATE TABLE t1; @@ -900,7 +900,7 @@ SELECT DATA_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' AND DATA_LENGTH 1008 # Rebuild back -ALTER TABLE t1 MODIFY COLUMN a TEXT CHARSET ucs2 COMPRESSED; +ALTER TABLE t1 MODIFY COLUMN a TEXT COMPRESSED CHARSET ucs2; SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -975,7 +975,7 @@ VARIABLE_NAME VARIABLE_VALUE COLUMN_COMPRESSIONS 2 COLUMN_DECOMPRESSIONS 10 # Make sure online add column works (requires InnoDB) -ALTER TABLE t1 ADD COLUMN b TEXT CHARSET ucs2 COMPRESSED DEFAULT "must be visible"; +ALTER TABLE t1 ADD COLUMN b TEXT COMPRESSED CHARSET ucs2 DEFAULT "must be visible"; SELECT LEFT(a, 10), LENGTH(a), b FROM t1; LEFT(a, 10) LENGTH(a) b aaaaaaaaaa 2000 must be visible @@ -1054,9 +1054,9 @@ DROP TABLE t1; # MDEV-13540 - Server crashes in copy or Assertion `0' failed in virtual # Field* Field_varstring_compressed::new_key_field # -CREATE TABLE t1 (c1 TEXT CHARSET ucs2 COMPRESSED) ENGINE=MyISAM; +CREATE TABLE t1 (c1 TEXT COMPRESSED CHARSET ucs2) ENGINE=MyISAM; INSERT IGNORE INTO t1 VALUES ('foo'),('bar'); -CREATE TABLE t2 (c2 TEXT CHARSET ucs2 COMPRESSED) ENGINE=MyISAM; +CREATE TABLE t2 (c2 TEXT COMPRESSED CHARSET ucs2) ENGINE=MyISAM; INSERT IGNORE INTO t2 VALUES ('qux'),('abc'); SELECT * FROM t1 WHERE c1 NOT IN ( SELECT c2 FROM t2 WHERE c2 = c1 ); c1 @@ -1067,7 +1067,7 @@ DROP TABLE t1, t2; # MDEV-13541 - Server crashes in next_breadth_first_tab or Assertion `0' # failed in Field_varstring_compressed::new_key_field # -CREATE TABLE t1 (c TEXT CHARSET ucs2 COMPRESSED) ENGINE=InnoDB; +CREATE TABLE t1 (c TEXT COMPRESSED CHARSET ucs2) ENGINE=InnoDB; INSERT INTO t1 VALUES ('foo'),('bar'); SELECT DISTINCT c FROM t1; c @@ -1297,13 +1297,15 @@ ERROR 42000: Incorrect column specifier for column 'a' CREATE TABLE t1(a BLOB COMPRESSED=unknown); ERROR HY000: Unknown compression method: unknown CREATE TABLE t1(a BLOB COMPRESSED COMPRESSED); +Warnings: +Warning 1287 'COMPRESSED after column attributes' is deprecated and will be removed in a future release. Please use COMPRESSED after data type instead DROP TABLE t1; CREATE TABLE t1(a INT); ALTER TABLE t1 MODIFY a INT COMPRESSED; ERROR 42000: Incorrect column specifier for column 'a' DROP TABLE t1; # Test CSV -CREATE TABLE t1(a BLOB NOT NULL COMPRESSED) ENGINE=CSV; +CREATE TABLE t1(a BLOB COMPRESSED NOT NULL) ENGINE=CSV; INSERT INTO t1 VALUES(REPEAT('a', 110)); SELECT LENGTH(a) FROM t1; LENGTH(a) @@ -1452,8 +1454,8 @@ DROP TABLE t1; # CREATE TABLE t1 ( -a VARCHAR(10) CHARACTER SET latin1 COMPRESSED, -b VARCHAR(10) CHARACTER SET utf8 COMPRESSED +a VARCHAR(10) COMPRESSED CHARACTER SET latin1, +b VARCHAR(10) COMPRESSED CHARACTER SET utf8 ); SELECT COLUMN_NAME, CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH FROM INFORMATION_SCHEMA.COLUMNS @@ -1475,7 +1477,7 @@ DROP TABLE t1; # # MDEV-16729 VARCHAR COMPRESSED is created with a wrong length for multi-byte character sets # -CREATE OR REPLACE TABLE t1 (a VARCHAR(1000) CHARACTER SET utf8 COMPRESSED); +CREATE OR REPLACE TABLE t1 (a VARCHAR(1000) COMPRESSED CHARACTER SET utf8); SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -1486,3 +1488,27 @@ WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1'; COLUMN_TYPE varchar(1000) /*!100301 COMPRESSED*/ DROP TABLE t1; +# +# MDEV-17363 - Compressed columns cannot be restored from dump +# +CREATE TABLE t1(a INT NOT NULL COMPRESSED); +ERROR 42000: Incorrect column specifier for column 'a' +SHOW WARNINGS; +Level Code Message +Warning 1287 'COMPRESSED after column attributes' is deprecated and will be removed in a future release. Please use COMPRESSED after data type instead +Error 1063 Incorrect column specifier for column 'a' +CREATE TABLE t1( +a JSON COMPRESSED, +b VARCHAR(1000) COMPRESSED BINARY, +c NVARCHAR(1000) COMPRESSED BINARY, +d TINYTEXT COMPRESSED BINARY +); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` longtext /*!100301 COMPRESSED*/ CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, + `b` varchar(1000) /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL, + `c` varchar(1000) /*!100301 COMPRESSED*/ CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, + `d` tinytext /*!100301 COMPRESSED*/ CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; diff --git a/mysql-test/main/column_compression.test b/mysql-test/main/column_compression.test index c9d0014ab9e..046bbe18aad 100644 --- a/mysql-test/main/column_compression.test +++ b/mysql-test/main/column_compression.test @@ -20,7 +20,7 @@ let $typec= VARCHAR(10000) COMPRESSED; let $typeu= VARCHAR(10000); --source column_compression.inc -let $typec= TEXT CHARSET ucs2 COMPRESSED; +let $typec= TEXT COMPRESSED CHARSET ucs2; let $typeu= TEXT; --source column_compression.inc @@ -43,7 +43,7 @@ ALTER TABLE t1 MODIFY a INT COMPRESSED; DROP TABLE t1; --echo # Test CSV -CREATE TABLE t1(a BLOB NOT NULL COMPRESSED) ENGINE=CSV; +CREATE TABLE t1(a BLOB COMPRESSED NOT NULL) ENGINE=CSV; INSERT INTO t1 VALUES(REPEAT('a', 110)); SELECT LENGTH(a) FROM t1; ALTER TABLE t1 ENGINE=MyISAM; @@ -153,8 +153,8 @@ DROP TABLE t1; CREATE TABLE t1 ( - a VARCHAR(10) CHARACTER SET latin1 COMPRESSED, - b VARCHAR(10) CHARACTER SET utf8 COMPRESSED + a VARCHAR(10) COMPRESSED CHARACTER SET latin1, + b VARCHAR(10) COMPRESSED CHARACTER SET utf8 ); SELECT COLUMN_NAME, CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH FROM INFORMATION_SCHEMA.COLUMNS @@ -176,8 +176,25 @@ DROP TABLE t1; --echo # MDEV-16729 VARCHAR COMPRESSED is created with a wrong length for multi-byte character sets --echo # -CREATE OR REPLACE TABLE t1 (a VARCHAR(1000) CHARACTER SET utf8 COMPRESSED); +CREATE OR REPLACE TABLE t1 (a VARCHAR(1000) COMPRESSED CHARACTER SET utf8); SHOW CREATE TABLE t1; SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='test' AND TABLE_NAME='t1'; DROP TABLE t1; + + +--echo # +--echo # MDEV-17363 - Compressed columns cannot be restored from dump +--echo # +--error ER_WRONG_FIELD_SPEC +CREATE TABLE t1(a INT NOT NULL COMPRESSED); +SHOW WARNINGS; + +CREATE TABLE t1( + a JSON COMPRESSED, + b VARCHAR(1000) COMPRESSED BINARY, + c NVARCHAR(1000) COMPRESSED BINARY, + d TINYTEXT COMPRESSED BINARY +); +SHOW CREATE TABLE t1; +DROP TABLE t1; diff --git a/sql/field.cc b/sql/field.cc index c6bdb013cdf..97c99033d34 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -11105,20 +11105,30 @@ bool Column_definition::has_default_expression() bool Column_definition::set_compressed(const char *method) { + if (!method || !strcmp(method, zlib_compression_method->name)) + { + unireg_check= Field::TMYSQL_COMPRESSED; + compression_method_ptr= zlib_compression_method; + return false; + } + my_error(ER_UNKNOWN_COMPRESSION_METHOD, MYF(0), method); + return true; +} + + +bool Column_definition::set_compressed_deprecated(THD *thd, const char *method) +{ enum enum_field_types sql_type= real_field_type(); + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_WARN_DEPRECATED_SYNTAX, + ER_THD(thd, ER_WARN_DEPRECATED_SYNTAX), + "COMPRESSED after column attributes", + "COMPRESSED after data type"); /* We can't use f_is_blob here as pack_flag is not yet set */ if (sql_type == MYSQL_TYPE_VARCHAR || sql_type == MYSQL_TYPE_TINY_BLOB || sql_type == MYSQL_TYPE_BLOB || sql_type == MYSQL_TYPE_MEDIUM_BLOB || sql_type == MYSQL_TYPE_LONG_BLOB) - { - if (!method || !strcmp(method, zlib_compression_method->name)) - { - unireg_check= Field::TMYSQL_COMPRESSED; - compression_method_ptr= zlib_compression_method; - return false; - } - my_error(ER_UNKNOWN_COMPRESSION_METHOD, MYF(0), method); - } + return set_compressed(method); else my_error(ER_WRONG_FIELD_SPEC, MYF(0), field_name.str); return true; diff --git a/sql/field.h b/sql/field.h index 47952a4dfd8..738463718c4 100644 --- a/sql/field.h +++ b/sql/field.h @@ -4559,6 +4559,7 @@ public: *this= *def; } bool set_compressed(const char *method); + bool set_compressed_deprecated(THD *thd, const char *method); void set_compression_method(Compression_method *compression_method_arg) { compression_method_ptr= compression_method_arg; } Compression_method *compression_method() const diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index a333bd79dd3..5b9b54c4915 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -884,10 +884,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %parse-param { THD *thd } %lex-param { THD *thd } /* - Currently there are 52 shift/reduce conflicts. + Currently there are 72 shift/reduce conflicts. We should not introduce new conflicts any more. */ -%expect 52 +%expect 72 /* Comments for TOKENS. @@ -6998,25 +6998,25 @@ field_type_string: Lex->charset=&my_charset_bin; $$.set(&type_handler_string, $2); } - | varchar field_length opt_binary + | varchar field_length opt_compressed opt_binary { $$.set(&type_handler_varchar, $2); } - | VARCHAR2_ORACLE_SYM field_length opt_binary + | VARCHAR2_ORACLE_SYM field_length opt_compressed opt_binary { $$.set(&type_handler_varchar, $2); } - | nvarchar field_length opt_bin_mod + | nvarchar field_length opt_compressed opt_bin_mod { $$.set(&type_handler_varchar, $2); - bincmp_collation(national_charset_info, $3); + bincmp_collation(national_charset_info, $4); } - | VARBINARY field_length + | VARBINARY field_length opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_varchar, $2); } - | RAW_ORACLE_SYM field_length + | RAW_ORACLE_SYM field_length opt_compressed { Lex->charset= &my_charset_bin; $$.set(&type_handler_varchar, $2); @@ -7082,17 +7082,17 @@ field_type_temporal: field_type_lob: - TINYBLOB + TINYBLOB opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_tiny_blob); } - | BLOB_MARIADB_SYM opt_field_length + | BLOB_MARIADB_SYM opt_field_length opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_blob, $2); } - | BLOB_ORACLE_SYM opt_field_length + | BLOB_ORACLE_SYM opt_field_length opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_long_blob); @@ -7108,36 +7108,36 @@ field_type_lob: sym_group_geom.needed_define)); #endif } - | MEDIUMBLOB + | MEDIUMBLOB opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_medium_blob); } - | LONGBLOB + | LONGBLOB opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_long_blob); } - | LONG_SYM VARBINARY + | LONG_SYM VARBINARY opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_medium_blob); } - | LONG_SYM varchar opt_binary + | LONG_SYM varchar opt_compressed opt_binary { $$.set(&type_handler_medium_blob); } - | TINYTEXT opt_binary + | TINYTEXT opt_compressed opt_binary { $$.set(&type_handler_tiny_blob); } - | TEXT_SYM opt_field_length opt_binary + | TEXT_SYM opt_field_length opt_compressed opt_binary { $$.set(&type_handler_blob, $2); } - | MEDIUMTEXT opt_binary + | MEDIUMTEXT opt_compressed opt_binary { $$.set(&type_handler_medium_blob); } - | LONGTEXT opt_binary + | LONGTEXT opt_compressed opt_binary { $$.set(&type_handler_long_blob); } - | CLOB_ORACLE_SYM opt_binary + | CLOB_ORACLE_SYM opt_compressed opt_binary { $$.set(&type_handler_long_blob); } - | LONG_SYM opt_binary + | LONG_SYM opt_compressed opt_binary { $$.set(&type_handler_medium_blob); } - | JSON_SYM + | JSON_SYM opt_compressed { Lex->charset= &my_charset_utf8mb4_bin; $$.set(&type_handler_long_blob); @@ -7287,7 +7287,7 @@ attribute: } | COMPRESSED_SYM opt_compression_method { - if (unlikely(Lex->last_field->set_compressed($2))) + if (unlikely(Lex->last_field->set_compressed_deprecated(thd, $2))) MYSQL_YYABORT; } | serial_attribute @@ -7298,6 +7298,15 @@ opt_compression_method: | equal ident { $$= $2.str; } ; +opt_compressed: + /* empty */ {} + | COMPRESSED_SYM opt_compression_method + { + if (unlikely(Lex->last_field->set_compressed($2))) + MYSQL_YYABORT; + } + ; + asrow_attribute: not NULL_SYM { diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index 7d561e7c34a..89bb9d81579 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -278,10 +278,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %parse-param { THD *thd } %lex-param { THD *thd } /* - Currently there are 53 shift/reduce conflicts. + Currently there are 74 shift/reduce conflicts. We should not introduce new conflicts any more. */ -%expect 53 +%expect 74 /* Comments for TOKENS. @@ -6854,25 +6854,25 @@ field_type_string: Lex->charset=&my_charset_bin; $$.set(&type_handler_string, $2); } - | varchar field_length opt_binary + | varchar field_length opt_compressed opt_binary { $$.set(&type_handler_varchar, $2); } - | VARCHAR2_ORACLE_SYM field_length opt_binary + | VARCHAR2_ORACLE_SYM field_length opt_compressed opt_binary { $$.set(&type_handler_varchar, $2); } - | nvarchar field_length opt_bin_mod + | nvarchar field_length opt_compressed opt_bin_mod { $$.set(&type_handler_varchar, $2); - bincmp_collation(national_charset_info, $3); + bincmp_collation(national_charset_info, $4); } - | VARBINARY field_length + | VARBINARY field_length opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_varchar, $2); } - | RAW_ORACLE_SYM field_length + | RAW_ORACLE_SYM field_length opt_compressed { Lex->charset= &my_charset_bin; $$.set(&type_handler_varchar, $2); @@ -6980,17 +6980,17 @@ field_type_temporal: field_type_lob: - TINYBLOB + TINYBLOB opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_tiny_blob); } - | BLOB_MARIADB_SYM opt_field_length + | BLOB_MARIADB_SYM opt_field_length opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_blob, $2); } - | BLOB_ORACLE_SYM opt_field_length + | BLOB_ORACLE_SYM opt_field_length opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_long_blob); @@ -7006,36 +7006,36 @@ field_type_lob: sym_group_geom.needed_define)); #endif } - | MEDIUMBLOB + | MEDIUMBLOB opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_medium_blob); } - | LONGBLOB + | LONGBLOB opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_long_blob); } - | LONG_SYM VARBINARY + | LONG_SYM VARBINARY opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_medium_blob); } - | LONG_SYM varchar opt_binary + | LONG_SYM varchar opt_compressed opt_binary { $$.set(&type_handler_medium_blob); } - | TINYTEXT opt_binary + | TINYTEXT opt_compressed opt_binary { $$.set(&type_handler_tiny_blob); } - | TEXT_SYM opt_field_length opt_binary + | TEXT_SYM opt_field_length opt_compressed opt_binary { $$.set(&type_handler_blob, $2); } - | MEDIUMTEXT opt_binary + | MEDIUMTEXT opt_compressed opt_binary { $$.set(&type_handler_medium_blob); } - | LONGTEXT opt_binary + | LONGTEXT opt_compressed opt_binary { $$.set(&type_handler_long_blob); } - | CLOB_ORACLE_SYM opt_binary + | CLOB_ORACLE_SYM opt_compressed opt_binary { $$.set(&type_handler_long_blob); } - | LONG_SYM opt_binary + | LONG_SYM opt_compressed opt_binary { $$.set(&type_handler_medium_blob); } - | JSON_SYM + | JSON_SYM opt_compressed { Lex->charset= &my_charset_utf8mb4_bin; $$.set(&type_handler_long_blob); @@ -7211,7 +7211,7 @@ attribute: } | COMPRESSED_SYM opt_compression_method { - if (unlikely(Lex->last_field->set_compressed($2))) + if (unlikely(Lex->last_field->set_compressed_deprecated(thd, $2))) MYSQL_YYABORT; } | serial_attribute @@ -7222,6 +7222,15 @@ opt_compression_method: | equal ident { $$= $2.str; } ; +opt_compressed: + /* empty */ {} + | COMPRESSED_SYM opt_compression_method + { + if (unlikely(Lex->last_field->set_compressed($2))) + MYSQL_YYABORT; + } + ; + asrow_attribute: not NULL_SYM { |