Commit ce75d7e9 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

refs #5195 first step of add and drop key in alter table

git-svn-id: file:///svn/mysql/tokudb-engine/tokudb-engine@45854 c7de825b-a66e-492c-adef-691d508d4ae1
parent d9b044d9
......@@ -97,6 +97,47 @@ ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_
ulong handler_flags = fix_handler_flags(ha_alter_info, table, altered_table);
// add/drop index
#if 0
// turn this on when we support add and drop in the same statement
if (only_flags(handler_flags, Alter_inplace_info::DROP_INDEX + Alter_inplace_info::DROP_UNIQUE_INDEX +
Alter_inplace_info::ADD_INDEX + Alter_inplace_info::ADD_UNIQUE_INDEX)) {
if ((ha_alter_info->index_add_count > 0 || ha_alter_info->index_drop_count > 0) &&
!tables_have_same_keys(table, altered_table, false, false)) {
result = HA_ALTER_INPLACE_SHARED_LOCK;
// someday, allow multiple hot indexes via alter table add key. don't forget to change the store_lock function.
// for now, hot indexing is only supported via session variable with the create index sql command
if (ha_alter_info->index_add_count == 1 && ha_alter_info->index_drop_count == 0 &&
get_create_index_online(thd) && thd_sql_command(thd) == SQLCOM_CREATE_INDEX) {
result = HA_ALTER_INPLACE_NO_LOCK;
}
}
} else
#else
if (only_flags(handler_flags, Alter_inplace_info::ADD_INDEX + Alter_inplace_info::ADD_UNIQUE_INDEX)) {
if ((ha_alter_info->index_add_count > 0) &&
!tables_have_same_keys(table, altered_table, false, false)) {
result = HA_ALTER_INPLACE_SHARED_LOCK;
// someday, allow multiple hot indexes via alter table add key. don't forget to change the store_lock function.
// for now, hot indexing is only supported via session variable with the create index sql command
if (ha_alter_info->index_add_count == 1 && ha_alter_info->index_drop_count == 0 &&
get_create_index_online(thd) && thd_sql_command(thd) == SQLCOM_CREATE_INDEX) {
result = HA_ALTER_INPLACE_NO_LOCK;
}
}
} else
if (only_flags(handler_flags, Alter_inplace_info::DROP_INDEX + Alter_inplace_info::DROP_UNIQUE_INDEX)) {
if ((ha_alter_info->index_drop_count > 0) &&
!tables_have_same_keys(table, altered_table, false, false)) {
result = HA_ALTER_INPLACE_SHARED_LOCK;
}
} else
#endif
// column rename
if (only_flags(handler_flags, Alter_inplace_info::ALTER_COLUMN_NAME + Alter_inplace_info::ALTER_COLUMN_DEFAULT)) {
// we have identified a possible column rename,
......@@ -112,31 +153,7 @@ ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_
if (cr_supported)
result = HA_ALTER_INPLACE_NO_LOCK;
} else
// alter auto_increment (and nothing else)
if (only_flags(handler_flags, Alter_inplace_info::CHANGE_CREATE_OPTION) &&
create_info->used_fields == HA_CREATE_USED_AUTO) {
result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK;
} else
// alter row_format (and nothing else)
if (only_flags(handler_flags, Alter_inplace_info::CHANGE_CREATE_OPTION) &&
create_info->used_fields == HA_CREATE_USED_ROW_FORMAT) {
result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK;
} else
// add index (and nothing else)
if (only_flags(handler_flags, Alter_inplace_info::ADD_INDEX + Alter_inplace_info::ADD_UNIQUE_INDEX)) {
assert(ha_alter_info->index_drop_count == 0);
result = HA_ALTER_INPLACE_SHARED_LOCK;
// someday, allow multiple hot indexes via alter table add key. don't forget to change the store_lock function.
// for now, hot indexing is only supported via session variable with the create index sql command
if (get_create_index_online(thd) && ha_alter_info->index_add_count == 1 && thd_sql_command(thd) == SQLCOM_CREATE_INDEX)
result = HA_ALTER_INPLACE_NO_LOCK;
} else
// drop index (and nothing else)
if (only_flags(handler_flags, Alter_inplace_info::DROP_INDEX + Alter_inplace_info::DROP_UNIQUE_INDEX)) {
assert(ha_alter_info->index_add_count == 0);
result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK;;
} else
// add column (and nothing else)
// add column
if (only_flags(handler_flags, Alter_inplace_info::ADD_COLUMN + Alter_inplace_info::ALTER_COLUMN_ORDER)) {
u_int32_t added_columns[altered_table->s->fields];
u_int32_t num_added_columns = 0;
......@@ -152,7 +169,7 @@ ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_
result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK;
}
} else
// drop column (and nothing else)
// drop column
if (only_flags(handler_flags, Alter_inplace_info::DROP_COLUMN + Alter_inplace_info::ALTER_COLUMN_ORDER)) {
u_int32_t dropped_columns[table->s->fields];
u_int32_t num_dropped_columns = 0;
......@@ -167,8 +184,19 @@ ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_
}
result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK;
}
} else
if (only_flags(handler_flags, Alter_inplace_info::CHANGE_CREATE_OPTION)) {
// alter auto_increment
if (only_flags(create_info->used_fields, HA_CREATE_USED_AUTO)) {
result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK;
} else
// alter row_format
if (only_flags(create_info->used_fields, HA_CREATE_USED_ROW_FORMAT)) {
result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK;
}
}
// turn not supported into error if the slow alter table (copy) is disabled
if (result == HA_ALTER_INPLACE_NOT_SUPPORTED && get_disable_slow_alter(thd)) {
print_error(HA_ERR_UNSUPPORTED, MYF(0));
result = HA_ALTER_ERROR;
......@@ -194,25 +222,19 @@ ha_tokudb::inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alte
HA_CREATE_INFO *create_info = ha_alter_info->create_info;
ulong handler_flags = fix_handler_flags(ha_alter_info, table, altered_table);
if (error == 0 && (handler_flags & (Alter_inplace_info::ADD_INDEX + Alter_inplace_info::ADD_UNIQUE_INDEX))) {
error = alter_table_add_index(altered_table, ha_alter_info);
}
if (error == 0 && (handler_flags & (Alter_inplace_info::DROP_INDEX + Alter_inplace_info::DROP_UNIQUE_INDEX))) {
error = alter_table_drop_index(altered_table, ha_alter_info);
}
if (error == 0 && (handler_flags & Alter_inplace_info::ADD_COLUMN)) {
error = alter_table_add_or_drop_column(altered_table, ha_alter_info);
if (error == 0 && (handler_flags & (Alter_inplace_info::ADD_INDEX + Alter_inplace_info::ADD_UNIQUE_INDEX))) {
error = alter_table_add_index(altered_table, ha_alter_info);
}
if (error == 0 && (handler_flags & Alter_inplace_info::DROP_COLUMN)) {
if (error == 0 && (handler_flags & (Alter_inplace_info::ADD_COLUMN + Alter_inplace_info::DROP_COLUMN))) {
error = alter_table_add_or_drop_column(altered_table, ha_alter_info);
}
if (error == 0 && (handler_flags & Alter_inplace_info::CHANGE_CREATE_OPTION) &&
(create_info->used_fields & HA_CREATE_USED_AUTO)) {
if (error == 0 && (handler_flags & Alter_inplace_info::CHANGE_CREATE_OPTION) && (create_info->used_fields & HA_CREATE_USED_AUTO)) {
error = write_auto_inc_create(share->status_block, create_info->auto_increment_value, transaction);
}
if (error == 0 && (handler_flags & Alter_inplace_info::CHANGE_CREATE_OPTION) &&
(create_info->used_fields & HA_CREATE_USED_ROW_FORMAT)) {
if (error == 0 && (handler_flags & Alter_inplace_info::CHANGE_CREATE_OPTION) && (create_info->used_fields & HA_CREATE_USED_ROW_FORMAT)) {
enum toku_compression_method method = TOKU_NO_COMPRESSION;
method = row_type_to_compression_method(create_info->row_type);
......
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