diff --git a/mysql-test/main/vector2.result b/mysql-test/main/vector2.result index a59559e07c6..253ef8aecf7 100644 --- a/mysql-test/main/vector2.result +++ b/mysql-test/main/vector2.result @@ -141,6 +141,9 @@ execute stmt; Warnings: Note 1091 Can't DROP INDEX `v`; check that it exists execute stmt; +prepare stmt from 'alter table t drop index if exists v, add vector (v)'; +execute stmt; +execute stmt; show create table t; Table Create Table t CREATE TABLE `t` ( diff --git a/mysql-test/main/vector2.test b/mysql-test/main/vector2.test index 32d9dcaf22b..72089f8f6f1 100644 --- a/mysql-test/main/vector2.test +++ b/mysql-test/main/vector2.test @@ -112,6 +112,9 @@ create table t (a int, v vector(10) not null); prepare stmt from 'alter table t drop index if exists v, add vector (v) max_edges_per_node=10'; execute stmt; execute stmt; +prepare stmt from 'alter table t drop index if exists v, add vector (v)'; +execute stmt; +execute stmt; show create table t; drop table t; set mhnsw_distance_function= default; diff --git a/sql/create_options.cc b/sql/create_options.cc index e06c112a975..94228d1ee83 100644 --- a/sql/create_options.cc +++ b/sql/create_options.cc @@ -51,7 +51,7 @@ void engine_option_value::link(engine_option_value **start, if (opt) { opt->value= Value(); /* remove previous value */ - opt->parsed= TRUE; /* and don't issue warnings for it anymore */ + opt->parsed= TRUE; /* and don't issue warnings for it anymore */ } /* Add this option to the end of the list @@ -226,9 +226,11 @@ static const size_t ha_option_type_sizeof[]= bool extend_option_list(THD* thd, st_plugin_int *plugin, bool create, engine_option_value **option_list, - ha_create_table_option *rules, MEM_ROOT *root) + ha_create_table_option *rules) { DBUG_ENTER("extend_option_list"); + MEM_ROOT *root= thd->mem_root; + bool extended= false; for (ha_create_table_option *opt= rules; rules && opt->name; opt++) { @@ -262,6 +264,12 @@ bool extend_option_list(THD* thd, st_plugin_int *plugin, bool create, { engine_option_value *val= new (root) engine_option_value(name, value, opt->type != HA_OPTION_TYPE_ULL); + if (!extended) + { + void *pos= *option_list ? &(last->next) : option_list; + thd->register_item_tree_change((Item**)pos); + extended= true; + } val->link(option_list, &last); } } @@ -844,4 +852,3 @@ bool is_engine_option_known(engine_option_value *opt, } return false; } - diff --git a/sql/create_options.h b/sql/create_options.h index d21596a0e27..b92dfa394f3 100644 --- a/sql/create_options.h +++ b/sql/create_options.h @@ -118,14 +118,14 @@ bool parse_option_list(THD* thd, void *option_struct, bool extend_option_list(THD* thd, st_plugin_int *plugin, bool create, engine_option_value **option_list, - ha_create_table_option *rules, MEM_ROOT *root); + ha_create_table_option *rules); static inline bool extend_option_list(THD* thd, handlerton *hton, bool create, engine_option_value **option_list, - ha_create_table_option *rules, MEM_ROOT *root) + ha_create_table_option *rules) { return extend_option_list(thd, hton2plugin[hton->slot], create, option_list, - rules, root); + rules); } bool engine_table_options_frm_read(const uchar *buff, size_t length, diff --git a/sql/sql_class.h b/sql/sql_class.h index 2b6ea6b23b7..55ffde28735 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -4811,14 +4811,19 @@ public: return !stmt_arena->is_conventional(); } + void register_item_tree_change(Item **place) + { + /* TODO: check for OOM condition here */ + if (is_item_tree_change_register_required()) + nocheck_register_item_tree_change(place, *place, mem_root); + } + void change_item_tree(Item **place, Item *new_value) { DBUG_ENTER("THD::change_item_tree"); DBUG_PRINT("enter", ("Register: %p (%p) <- %p", *place, place, new_value)); - /* TODO: check for OOM condition here */ - if (is_item_tree_change_register_required()) - nocheck_register_item_tree_change(place, *place, mem_root); + register_item_tree_change(place); *place= new_value; DBUG_VOID_RETURN; } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 93c62b7582b..7611c1a33b4 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3006,8 +3006,7 @@ mysql_prepare_create_table_finalize(THD *thd, HA_CREATE_INFO *create_info, auto_increment++; extend_option_list(thd, create_info->db_type, !sql_field->field, &sql_field->option_list, - create_info->db_type->field_options, - thd->stmt_arena->mem_root); + create_info->db_type->field_options); if (parse_option_list(thd, &sql_field->option_struct, &sql_field->option_list, create_info->db_type->field_options, FALSE, @@ -3295,7 +3294,7 @@ mysql_prepare_create_table_finalize(THD *thd, HA_CREATE_INFO *create_info, key_info->algorithm= key->key_create_info.algorithm; key_info->option_list= key->option_list; extend_option_list(thd, index_plugin, !key->old, &key_info->option_list, - index_options, thd->stmt_arena->mem_root); + index_options); if (parse_option_list(thd, &key_info->option_struct, &key_info->option_list, index_options, FALSE, thd->mem_root)) DBUG_RETURN(TRUE); @@ -3891,10 +3890,8 @@ without_overlaps_err: ER_THD(thd, ER_UNKNOWN_OPTION), "transactional"); extend_option_list(thd, file->partition_ht(), - create_table_mode > C_ALTER_TABLE, - &create_info->option_list, - file->partition_ht()->table_options, - thd->stmt_arena->mem_root); + !thd->lex->create_like() && create_table_mode > C_ALTER_TABLE, + &create_info->option_list, file->partition_ht()->table_options); if (parse_option_list(thd, &create_info->option_struct, &create_info->option_list, file->partition_ht()->table_options, FALSE,