diff options
author | Sergei Golubchik <sergii@pisem.net> | 2014-07-08 19:39:27 +0200 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2014-07-08 19:39:27 +0200 |
commit | 086a81986bfa5b1a6c3d0594a1e4017e45d51e42 (patch) | |
tree | 9aa85b4a9ebfae62f92f7efda981cd755f40d457 | |
parent | 5045615cd945b137c1f6b7c5e4c1bb960eb3b287 (diff) | |
download | mariadb-git-086a81986bfa5b1a6c3d0594a1e4017e45d51e42.tar.gz |
MDEV-5867 ALTER TABLE t1 ENGINE=InnoDB keeps bad options when t1 ENGINE is CONNECT
Comment out unknown options in SHOW CREATE TABLE unless IGNORE_BAD_TABLE_OPTIONS is used
-rw-r--r-- | mysql-test/r/table_options-5867.result | 37 | ||||
-rw-r--r-- | mysql-test/suite/rpl/r/rpl_table_options.result | 6 | ||||
-rw-r--r-- | mysql-test/suite/rpl/t/rpl_table_options.test | 2 | ||||
-rw-r--r-- | mysql-test/t/table_options-5867.test | 30 | ||||
-rw-r--r-- | sql/create_options.cc | 17 | ||||
-rw-r--r-- | sql/create_options.h | 2 | ||||
-rw-r--r-- | sql/sql_show.cc | 38 | ||||
-rw-r--r-- | storage/connect/mysql-test/connect/r/alter.result | 11 | ||||
-rw-r--r-- | storage/connect/mysql-test/connect/t/alter.test | 6 |
9 files changed, 142 insertions, 7 deletions
diff --git a/mysql-test/r/table_options-5867.result b/mysql-test/r/table_options-5867.result new file mode 100644 index 00000000000..21041c7c5c3 --- /dev/null +++ b/mysql-test/r/table_options-5867.result @@ -0,0 +1,37 @@ +install soname 'ha_example'; +set sql_mode='ignore_bad_table_options'; +create table t1 ( +a int complex='c,f,f,f' invalid=3 +) engine=example ull=10000 str='dskj' one_or_two='one' yesno=0 +foobar=barfoo; +Warnings: +Warning 1911 Unknown option 'invalid' +Warning 1911 Unknown option 'foobar' +create table t2 (a int, key (a) some_option=2014); +Warnings: +Warning 1911 Unknown option 'some_option' +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL `complex`='c,f,f,f' `invalid`=3 +) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `ull`=10000 `str`='dskj' `one_or_two`='one' `yesno`=0 `foobar`=barfoo `VAROPT`='5' +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL, + KEY `a` (`a`) `some_option`=2014 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +set sql_mode=''; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL `complex`='c,f,f,f' /* `invalid`=3 */ +) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `ull`=10000 `str`='dskj' `one_or_two`='one' `yesno`=0 /* `foobar`=barfoo */ `VAROPT`='5' +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL, + KEY `a` (`a`) /* `some_option`=2014 */ +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1, t2; +uninstall soname 'ha_example'; diff --git a/mysql-test/suite/rpl/r/rpl_table_options.result b/mysql-test/suite/rpl/r/rpl_table_options.result index d69570a1709..a94d6e9bc2f 100644 --- a/mysql-test/suite/rpl/r/rpl_table_options.result +++ b/mysql-test/suite/rpl/r/rpl_table_options.result @@ -12,6 +12,12 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 /* `ull`=12340 */ +set sql_mode=ignore_bad_table_options; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 `ull`=12340 drop table t1; set storage_engine=default; diff --git a/mysql-test/suite/rpl/t/rpl_table_options.test b/mysql-test/suite/rpl/t/rpl_table_options.test index 12ff1ca457b..3f52444a3c7 100644 --- a/mysql-test/suite/rpl/t/rpl_table_options.test +++ b/mysql-test/suite/rpl/t/rpl_table_options.test @@ -23,6 +23,8 @@ show create table t1; sync_slave_with_master; connection slave; show create table t1; +set sql_mode=ignore_bad_table_options; +show create table t1; connection master; drop table t1; diff --git a/mysql-test/t/table_options-5867.test b/mysql-test/t/table_options-5867.test new file mode 100644 index 00000000000..153ec08e675 --- /dev/null +++ b/mysql-test/t/table_options-5867.test @@ -0,0 +1,30 @@ +# +# MDEV-5867 ALTER TABLE t1 ENGINE=InnoDB keeps bad options when t1 ENGINE is CONNECT +# +# verify that SHOW CREATE TABLE hides unknown options when IGNORE_BAD_TABLE_OPTIONS is not set + +--source include/have_example_plugin.inc +--source include/not_embedded.inc + +install soname 'ha_example'; + +set sql_mode='ignore_bad_table_options'; +create table t1 ( + a int complex='c,f,f,f' invalid=3 +) engine=example ull=10000 str='dskj' one_or_two='one' yesno=0 + foobar=barfoo; + +create table t2 (a int, key (a) some_option=2014); + +show create table t1; +show create table t2; + +set sql_mode=''; + +show create table t1; +show create table t2; + +drop table t1, t2; + +uninstall soname 'ha_example'; + diff --git a/sql/create_options.cc b/sql/create_options.cc index d60639a4f4a..09153f7e35c 100644 --- a/sql/create_options.cc +++ b/sql/create_options.cc @@ -775,3 +775,20 @@ engine_option_value *merge_engine_table_options(engine_option_value *first, &first, &end); DBUG_RETURN(first); } + +bool is_engine_option_known(engine_option_value *opt, + ha_create_table_option *rules) +{ + if (!rules) + return false; + + for (; rules->name; rules++) + { + if (!my_strnncoll(system_charset_info, + (uchar*)rules->name, rules->name_length, + (uchar*)opt->name.str, opt->name.length)) + return true; + } + return false; +} + diff --git a/sql/create_options.h b/sql/create_options.h index d6b48822c49..eb21f291ff4 100644 --- a/sql/create_options.h +++ b/sql/create_options.h @@ -99,4 +99,6 @@ uchar *engine_table_options_frm_image(uchar *buff, bool engine_options_differ(void *old_struct, void *new_struct, ha_create_table_option *rules); +bool is_engine_option_known(engine_option_value *opt, + ha_create_table_option *rules); #endif diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 40b7dc4e950..025eee72878 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1519,13 +1519,34 @@ static bool get_field_default_value(THD *thd, Field *field, String *def_value, @param thd thread handler @param packet string to append @param opt list of options + @param check_options only print known options + @param rules list of known options */ static void append_create_options(THD *thd, String *packet, - engine_option_value *opt) + engine_option_value *opt, + bool check_options, + ha_create_table_option *rules) { + bool in_comment= false; for(; opt; opt= opt->next) { + if (check_options) + { + if (is_engine_option_known(opt, rules)) + { + if (in_comment) + packet->append(STRING_WITH_LEN(" */")); + in_comment= false; + } + else + { + if (!in_comment) + packet->append(STRING_WITH_LEN(" /*")); + in_comment= true; + } + } + DBUG_ASSERT(opt->value.str); packet->append(' '); append_identifier(thd, packet, opt->name.str, opt->name.length); @@ -1535,6 +1556,8 @@ static void append_create_options(THD *thd, String *packet, else packet->append(opt->value.str, opt->value.length); } + if (in_comment) + packet->append(STRING_WITH_LEN(" */")); } /* @@ -1585,6 +1608,8 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, MODE_MYSQL40); bool show_table_options= !(sql_mode & MODE_NO_TABLE_OPTIONS) && !foreign_db_mode; + bool check_options= !(sql_mode & MODE_IGNORE_BAD_TABLE_OPTIONS) && + !create_info_arg; handlerton *hton; my_bitmap_map *old_map; int error= 0; @@ -1734,7 +1759,8 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, packet->append(STRING_WITH_LEN(" COMMENT ")); append_unescaped(packet, field->comment.str, field->comment.length); } - append_create_options(thd, packet, field->option_list); + append_create_options(thd, packet, field->option_list, check_options, + hton->field_options); } key_info= table->key_info; @@ -1801,7 +1827,8 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, append_identifier(thd, packet, parser_name->str, parser_name->length); packet->append(STRING_WITH_LEN(" */ ")); } - append_create_options(thd, packet, key_info->option_list); + append_create_options(thd, packet, key_info->option_list, check_options, + hton->index_options); } /* @@ -1952,7 +1979,8 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet, packet->append(STRING_WITH_LEN(" CONNECTION=")); append_unescaped(packet, share->connect_string.str, share->connect_string.length); } - append_create_options(thd, packet, share->option_list); + append_create_options(thd, packet, share->option_list, check_options, + hton->table_options); append_directory(thd, packet, "DATA", create_info.data_file_name); append_directory(thd, packet, "INDEX", create_info.index_file_name); } @@ -5129,7 +5157,7 @@ static int get_schema_tables_record(THD *thd, TABLE_LIST *tables, str.qs_append(STRING_WITH_LEN(" transactional=")); str.qs_append(ha_choice_values[(uint) share->transactional]); } - append_create_options(thd, &str, share->option_list); + append_create_options(thd, &str, share->option_list, false, 0); if (str.length()) table->field[19]->store(str.ptr()+1, str.length()-1, cs); diff --git a/storage/connect/mysql-test/connect/r/alter.result b/storage/connect/mysql-test/connect/r/alter.result index ccfae3f4ddb..e86628e2467 100644 --- a/storage/connect/mysql-test/connect/r/alter.result +++ b/storage/connect/mysql-test/connect/r/alter.result @@ -218,13 +218,22 @@ Three 3 # Changing to another engine is Ok # However, the data file is not deleted. # -ALTER TABLE t1 ENGINE=MARIA; +ALTER TABLE t1 ENGINE=ARIA; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` char(10) NOT NULL /* `FLAG`=11 */, + `c` int(11) NOT NULL /* `FLAG`=0 */ +) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 /* `TABLE_TYPE`=fix `FILE_NAME`='tf1.txt' `ENDING`=1 */ +set @old_sql_mode=@@sql_mode; +set sql_mode=ignore_bad_table_options; SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `d` char(10) NOT NULL `FLAG`=11, `c` int(11) NOT NULL `FLAG`=0 ) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 `TABLE_TYPE`=fix `FILE_NAME`='tf1.txt' `ENDING`=1 +set sql_mode=@old_sql_mode; SELECT * from t1; d c One 1 diff --git a/storage/connect/mysql-test/connect/t/alter.test b/storage/connect/mysql-test/connect/t/alter.test index 299381b925a..49f34996bbd 100644 --- a/storage/connect/mysql-test/connect/t/alter.test +++ b/storage/connect/mysql-test/connect/t/alter.test @@ -105,8 +105,12 @@ SELECT * FROM t1; --echo # Changing to another engine is Ok
--echo # However, the data file is not deleted.
--echo #
-ALTER TABLE t1 ENGINE=MARIA;
+ALTER TABLE t1 ENGINE=ARIA;
SHOW CREATE TABLE t1;
+set @old_sql_mode=@@sql_mode;
+set sql_mode=ignore_bad_table_options;
+SHOW CREATE TABLE t1;
+set sql_mode=@old_sql_mode;
SELECT * from t1;
SELECT * from t2;
|