summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2019-06-18 04:58:15 +0400
committerAlexander Barkov <bar@mariadb.com>2019-06-18 07:48:08 +0400
commit5352e9687a86094d19aaea605970487516e99ab5 (patch)
tree40f765c43fcfd46d53e56edd4753223f0000cced /sql
parent3784ed7a623ccc55a4755efeeb2f9ba06c7baf4e (diff)
downloadmariadb-git-5352e9687a86094d19aaea605970487516e99ab5.tar.gz
MDEV-17363 - Compressed columns cannot be restored from dump
In collaboration with Sergey Vojtovich <svoj@mariadb.org> The COMPRESSED clause is now a part of the data type and goes immediately after the data type and length, but before the CHARACTER SET clause, and before column attributes such as DEFAULT, COLLATE, ON UPDATE, SYSTEM VERSIONING, engine specific column attributes. In the old reduction, the COMPRESSED clause was a column attribute. New syntax: <varchar or text data type> <length> <compression> <character set> <column attributes> <varbinary or blob data type> <length> <compression> <column attributes> New syntax examples: VARCHAR(1000) COMPRESSED CHARACTER SET latin1 DEFAULT '' BLOB COMPRESSED DEFAULT '' Deprecate syntax examples: VARCHAR(1000) CHARACTER SET latin1 COMPRESSED DEFAULT '' TEXT CHARACTER SET latin1 DEFAULT '' COMPRESSED VARBINARY(1000) DEFAULT '' COMPRESSED As a side effect: - COMPRESSED is not valid as an SP label name in SQL/PSM routines any more (but it's still valid as an SP label name in sql_mode=ORACLE) - COMPRESSED is now allowed in combination with GENERATED ALWAYS AS: TEXT COMPRESSED GENERATED ALWAYS AS REPEAT('a',1000)
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc46
-rw-r--r--sql/field.h4
-rw-r--r--sql/sql_yacc.yy108
-rw-r--r--sql/sql_yacc_ora.yy113
4 files changed, 190 insertions, 81 deletions
diff --git a/sql/field.cc b/sql/field.cc
index c6bdb013cdf..842f92e858f 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -11105,20 +11105,48 @@ 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)
+{
+ push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
+ ER_WARN_DEPRECATED_SYNTAX,
+ ER_THD(thd, ER_WARN_DEPRECATED_SYNTAX),
+ "<data type> <character set clause> ... COMPRESSED...",
+ "'<data type> COMPRESSED... <character set clause> ...'");
+ return set_compressed(method);
+}
+
+
+bool
+Column_definition::set_compressed_deprecated_column_attribute(THD *thd,
+ const char *pos,
+ const char *method)
+{
+ if (compression_method_ptr)
+ {
+ /*
+ Compression method has already been set, e.g.:
+ a VARCHAR(10) COMPRESSED DEFAULT 10 COMPRESSED
+ */
+ thd->parse_error(ER_SYNTAX_ERROR, pos);
+ return true;
+ }
enum enum_field_types sql_type= real_field_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_deprecated(thd, 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..3e5b84f9249 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -4559,6 +4559,10 @@ public:
*this= *def;
}
bool set_compressed(const char *method);
+ bool set_compressed_deprecated(THD *thd, const char *method);
+ bool set_compressed_deprecated_column_attribute(THD *thd,
+ const char *pos,
+ 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 814017f0231..e844c500b77 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -2092,7 +2092,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
ref_list opt_match_clause opt_on_update_delete use
opt_delete_options opt_delete_option varchar nchar nvarchar
opt_outer table_list table_name table_alias_ref_list table_alias_ref
- opt_attribute opt_attribute_list attribute column_list column_list_id
+ attribute attribute_list
+ compressed_deprecated_data_type_attribute
+ compressed_deprecated_column_attribute
+ column_list column_list_id
opt_column_list grant_privileges grant_ident grant_list grant_option
object_privilege object_privilege_list user_list user_and_role_list
rename_list table_or_tables
@@ -6779,7 +6782,10 @@ opt_asrow_attribute_list:
;
field_def:
- opt_attribute
+ /* empty */ { }
+ | attribute_list
+ | attribute_list compressed_deprecated_column_attribute
+ | attribute_list compressed_deprecated_column_attribute attribute_list
| opt_generated_always AS virtual_column_func
{
Lex->last_field->vcol_info= $3;
@@ -6965,6 +6971,13 @@ field_type_numeric:
;
+opt_binary_and_compression:
+ /* empty */
+ | binary
+ | binary compressed_deprecated_data_type_attribute
+ | compressed opt_binary
+ ;
+
field_type_string:
char opt_field_length_default_1 opt_binary
{
@@ -6980,25 +6993,25 @@ field_type_string:
Lex->charset=&my_charset_bin;
$$.set(&type_handler_string, $2);
}
- | varchar field_length opt_binary
+ | varchar field_length opt_binary_and_compression
{
$$.set(&type_handler_varchar, $2);
}
- | VARCHAR2_ORACLE_SYM field_length opt_binary
+ | VARCHAR2_ORACLE_SYM field_length opt_binary_and_compression
{
$$.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);
@@ -7064,17 +7077,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);
@@ -7090,36 +7103,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_binary_and_compression
{ $$.set(&type_handler_medium_blob); }
- | TINYTEXT opt_binary
+ | TINYTEXT opt_binary_and_compression
{ $$.set(&type_handler_tiny_blob); }
- | TEXT_SYM opt_field_length opt_binary
+ | TEXT_SYM opt_field_length opt_binary_and_compression
{ $$.set(&type_handler_blob, $2); }
- | MEDIUMTEXT opt_binary
+ | MEDIUMTEXT opt_binary_and_compression
{ $$.set(&type_handler_medium_blob); }
- | LONGTEXT opt_binary
+ | LONGTEXT opt_binary_and_compression
{ $$.set(&type_handler_long_blob); }
- | CLOB_ORACLE_SYM opt_binary
+ | CLOB_ORACLE_SYM opt_binary_and_compression
{ $$.set(&type_handler_long_blob); }
- | LONG_SYM opt_binary
+ | LONG_SYM opt_binary_and_compression
{ $$.set(&type_handler_medium_blob); }
- | JSON_SYM
+ | JSON_SYM opt_compressed
{
Lex->charset= &my_charset_utf8mb4_bin;
$$.set(&type_handler_long_blob);
@@ -7233,13 +7246,9 @@ opt_precision:
| precision { $$= $1; }
;
-opt_attribute:
- /* empty */ {}
- | opt_attribute_list {}
- ;
-opt_attribute_list:
- opt_attribute_list attribute {}
+attribute_list:
+ attribute_list attribute {}
| attribute
;
@@ -7267,11 +7276,6 @@ attribute:
$2->name,Lex->charset->csname));
Lex->last_field->charset= $2;
}
- | COMPRESSED_SYM opt_compression_method
- {
- if (unlikely(Lex->last_field->set_compressed($2)))
- MYSQL_YYABORT;
- }
| serial_attribute
;
@@ -7280,6 +7284,36 @@ opt_compression_method:
| equal ident { $$= $2.str; }
;
+opt_compressed:
+ /* empty */ {}
+ | compressed { }
+ ;
+
+compressed:
+ COMPRESSED_SYM opt_compression_method
+ {
+ if (unlikely(Lex->last_field->set_compressed($2)))
+ MYSQL_YYABORT;
+ }
+ ;
+
+compressed_deprecated_data_type_attribute:
+ COMPRESSED_SYM opt_compression_method
+ {
+ if (unlikely(Lex->last_field->set_compressed_deprecated(thd, $2)))
+ MYSQL_YYABORT;
+ }
+ ;
+
+compressed_deprecated_column_attribute:
+ COMPRESSED_SYM opt_compression_method
+ {
+ if (unlikely(Lex->last_field->
+ set_compressed_deprecated_column_attribute(thd, $1.pos(), $2)))
+ MYSQL_YYABORT;
+ }
+ ;
+
asrow_attribute:
not NULL_SYM
{
@@ -7438,7 +7472,11 @@ charset_or_alias:
opt_binary:
/* empty */ { bincmp_collation(NULL, false); }
- | BYTE_SYM { bincmp_collation(&my_charset_bin, false); }
+ | binary {}
+ ;
+
+binary:
+ BYTE_SYM { bincmp_collation(&my_charset_bin, false); }
| charset_or_alias opt_bin_mod { bincmp_collation($1, $2); }
| BINARY { bincmp_collation(NULL, true); }
| BINARY charset_or_alias { bincmp_collation($2, true); }
@@ -15713,6 +15751,7 @@ keyword_sp_var_not_label:
| COLUMN_DELETE_SYM
| COLUMN_GET_SYM
| COMMENT_SYM
+ | COMPRESSED_SYM
| DEALLOCATE_SYM
| EXAMINED_SYM
| EXCLUDE_SYM
@@ -15925,7 +15964,6 @@ keyword_sp_var_and_label:
| COMMITTED_SYM
| COMPACT_SYM
| COMPLETION_SYM
- | COMPRESSED_SYM
| CONCURRENT
| CONNECTION_SYM
| CONSISTENT_SYM
diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy
index fcf0dc01562..1ba77dcd16e 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 55 shift/reduce conflicts.
We should not introduce new conflicts any more.
*/
-%expect 53
+%expect 55
/*
Comments for TOKENS.
@@ -1495,7 +1495,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
ref_list opt_match_clause opt_on_update_delete use
opt_delete_options opt_delete_option varchar nchar nvarchar
opt_outer table_list table_name table_alias_ref_list table_alias_ref
- opt_attribute opt_attribute_list attribute column_list column_list_id
+ attribute attribute_list
+ compressed_deprecated_data_type_attribute
+ compressed_deprecated_column_attribute
+ column_list column_list_id
opt_column_list grant_privileges grant_ident grant_list grant_option
object_privilege object_privilege_list user_list user_and_role_list
rename_list table_or_tables
@@ -6625,7 +6628,10 @@ opt_asrow_attribute_list:
;
field_def:
- opt_attribute
+ /* empty */ { }
+ | attribute_list
+ | attribute_list compressed_deprecated_column_attribute
+ | attribute_list compressed_deprecated_column_attribute attribute_list
| opt_generated_always AS virtual_column_func
{
Lex->last_field->vcol_info= $3;
@@ -6821,6 +6827,13 @@ field_type_numeric:
;
+opt_binary_and_compression:
+ /* empty */
+ | binary
+ | binary compressed_deprecated_data_type_attribute
+ | compressed opt_binary
+ ;
+
field_type_string:
char opt_field_length_default_1 opt_binary
{
@@ -6836,25 +6849,25 @@ field_type_string:
Lex->charset=&my_charset_bin;
$$.set(&type_handler_string, $2);
}
- | varchar field_length opt_binary
+ | varchar field_length opt_binary_and_compression
{
$$.set(&type_handler_varchar, $2);
}
- | VARCHAR2_ORACLE_SYM field_length opt_binary
+ | VARCHAR2_ORACLE_SYM field_length opt_binary_and_compression
{
$$.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);
@@ -6962,17 +6975,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);
@@ -6988,36 +7001,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_binary_and_compression
{ $$.set(&type_handler_medium_blob); }
- | TINYTEXT opt_binary
+ | TINYTEXT opt_binary_and_compression
{ $$.set(&type_handler_tiny_blob); }
- | TEXT_SYM opt_field_length opt_binary
+ | TEXT_SYM opt_field_length opt_binary_and_compression
{ $$.set(&type_handler_blob, $2); }
- | MEDIUMTEXT opt_binary
+ | MEDIUMTEXT opt_binary_and_compression
{ $$.set(&type_handler_medium_blob); }
- | LONGTEXT opt_binary
+ | LONGTEXT opt_binary_and_compression
{ $$.set(&type_handler_long_blob); }
- | CLOB_ORACLE_SYM opt_binary
+ | CLOB_ORACLE_SYM opt_binary_and_compression
{ $$.set(&type_handler_long_blob); }
- | LONG_SYM opt_binary
+ | LONG_SYM opt_binary_and_compression
{ $$.set(&type_handler_medium_blob); }
- | JSON_SYM
+ | JSON_SYM opt_compressed
{
Lex->charset= &my_charset_utf8mb4_bin;
$$.set(&type_handler_long_blob);
@@ -7157,13 +7170,9 @@ opt_precision:
| precision { $$= $1; }
;
-opt_attribute:
- /* empty */ {}
- | opt_attribute_list {}
- ;
-opt_attribute_list:
- opt_attribute_list attribute {}
+attribute_list:
+ attribute_list attribute {}
| attribute
;
@@ -7191,11 +7200,6 @@ attribute:
$2->name,Lex->charset->csname));
Lex->last_field->charset= $2;
}
- | COMPRESSED_SYM opt_compression_method
- {
- if (unlikely(Lex->last_field->set_compressed($2)))
- MYSQL_YYABORT;
- }
| serial_attribute
;
@@ -7204,6 +7208,36 @@ opt_compression_method:
| equal ident { $$= $2.str; }
;
+opt_compressed:
+ /* empty */ {}
+ | compressed { }
+ ;
+
+compressed:
+ COMPRESSED_SYM opt_compression_method
+ {
+ if (unlikely(Lex->last_field->set_compressed($2)))
+ MYSQL_YYABORT;
+ }
+ ;
+
+compressed_deprecated_data_type_attribute:
+ COMPRESSED_SYM opt_compression_method
+ {
+ if (unlikely(Lex->last_field->set_compressed_deprecated(thd, $2)))
+ MYSQL_YYABORT;
+ }
+ ;
+
+compressed_deprecated_column_attribute:
+ COMPRESSED_SYM opt_compression_method
+ {
+ if (unlikely(Lex->last_field->
+ set_compressed_deprecated_column_attribute(thd, $1.pos(), $2)))
+ MYSQL_YYABORT;
+ }
+ ;
+
asrow_attribute:
not NULL_SYM
{
@@ -7375,7 +7409,11 @@ charset_or_alias:
opt_binary:
/* empty */ { bincmp_collation(NULL, false); }
- | BYTE_SYM { bincmp_collation(&my_charset_bin, false); }
+ | binary {}
+ ;
+
+binary:
+ BYTE_SYM { bincmp_collation(&my_charset_bin, false); }
| charset_or_alias opt_bin_mod { bincmp_collation($1, $2); }
| BINARY { bincmp_collation(NULL, true); }
| BINARY charset_or_alias { bincmp_collation($2, true); }
@@ -15648,6 +15686,7 @@ keyword_label:
| keyword_sp_var_and_label
| keyword_sysvar_type
| FUNCTION_SYM
+ | COMPRESSED_SYM
;
keyword_sysvar_name:
@@ -15717,6 +15756,7 @@ keyword_sp_var_not_label:
| COLUMN_DELETE_SYM
| COLUMN_GET_SYM
| COMMENT_SYM
+ | COMPRESSED_SYM
| DEALLOCATE_SYM
| EXAMINED_SYM
| EXCLUDE_SYM
@@ -15929,7 +15969,6 @@ keyword_sp_var_and_label:
| COMMITTED_SYM
| COMPACT_SYM
| COMPLETION_SYM
- | COMPRESSED_SYM
| CONCURRENT
| CONNECTION_SYM
| CONSISTENT_SYM