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

rfs #5258 fix 5.5 alter add key, add unique key on mainline

git-svn-id: file:///svn/mysql/tokudb-engine/tokudb-engine@45778 c7de825b-a66e-492c-adef-691d508d4ae1
parent b500a795
...@@ -695,6 +695,13 @@ public: ...@@ -695,6 +695,13 @@ public:
bool incremented_num_DBs, modified_DBs; bool incremented_num_DBs, modified_DBs;
}; };
// true if some bit in mask is set and no bit in ~mask is set
// otherwise false
static bool
only_flags(uint bits, uint mask) {
return (bits & mask) != 0 && (bits & ~mask) == 0;
}
enum_alter_inplace_result enum_alter_inplace_result
ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_info *ha_alter_info) { ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_info *ha_alter_info) {
TOKUDB_DBUG_ENTER("check_if_supported_alter"); TOKUDB_DBUG_ENTER("check_if_supported_alter");
...@@ -720,39 +727,32 @@ ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_ ...@@ -720,39 +727,32 @@ ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_
} }
// column rename // column rename
if ((ha_alter_info->handler_flags & ~(Alter_inplace_info::ALTER_COLUMN_NAME + Alter_inplace_info::ALTER_COLUMN_DEFAULT)) == 0) { if (only_flags(ha_alter_info->handler_flags, Alter_inplace_info::ALTER_COLUMN_NAME + Alter_inplace_info::ALTER_COLUMN_DEFAULT)) {
// we have identified a possible column rename, // we have identified a possible column rename,
// but let's do some more checks // but let's do some more checks
// we will only allow an hcr if there are no changes // we will only allow an hcr if there are no changes
// in column positions // in column positions (ALTER_COLUMN_ORDER is not set)
#if 0 // TODO
if (alter_info->contains_first_or_after) { // now need to verify that one and only one column
result = HA_ALTER_INPLACE_NOT_SUPPORTED; // has changed only its name. If we find anything to
} else // the contrary, we don't allow it, also check indexes
#endif bool cr_supported = column_rename_supported(ha_alter_info, table, altered_table);
{ if (cr_supported)
// now need to verify that one and only one column result = HA_ALTER_INPLACE_NO_LOCK;
// has changed only its name. If we find anything to
// the contrary, we don't allow it, also check indexes
bool cr_supported = column_rename_supported(ha_alter_info, table, altered_table);
if (cr_supported)
result = HA_ALTER_INPLACE_NO_LOCK;
}
} else } else
// alter auto_increment (and nothing else) // alter auto_increment (and nothing else)
if (ha_alter_info->handler_flags == Alter_inplace_info::CHANGE_CREATE_OPTION && if (only_flags(ha_alter_info->handler_flags, Alter_inplace_info::CHANGE_CREATE_OPTION) &&
create_info->used_fields == HA_CREATE_USED_AUTO) { create_info->used_fields == HA_CREATE_USED_AUTO) {
result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK; result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK;
} else } else
// alter row_format (and nothing else) // alter row_format (and nothing else)
if (ha_alter_info->handler_flags == Alter_inplace_info::CHANGE_CREATE_OPTION && if (only_flags(ha_alter_info->handler_flags, Alter_inplace_info::CHANGE_CREATE_OPTION) &&
create_info->used_fields == HA_CREATE_USED_ROW_FORMAT) { create_info->used_fields == HA_CREATE_USED_ROW_FORMAT) {
result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK; result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK;
} else } else
// add index (and nothing else) // add index (and nothing else)
if (ha_alter_info->handler_flags == Alter_inplace_info::ADD_INDEX || if (only_flags(ha_alter_info->handler_flags, Alter_inplace_info::ADD_INDEX + Alter_inplace_info::ADD_UNIQUE_INDEX)) {
ha_alter_info->handler_flags == Alter_inplace_info::ADD_UNIQUE_INDEX) { // && tables_have_same_keys TODO???
assert(ha_alter_info->index_drop_count == 0); assert(ha_alter_info->index_drop_count == 0);
result = HA_ALTER_INPLACE_SHARED_LOCK; 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. // someday, allow multiple hot indexes via alter table add key. don't forget to change the store_lock function.
...@@ -761,14 +761,12 @@ ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_ ...@@ -761,14 +761,12 @@ ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_
result = HA_ALTER_INPLACE_NO_LOCK; result = HA_ALTER_INPLACE_NO_LOCK;
} else } else
// drop index (and nothing else) // drop index (and nothing else)
if (ha_alter_info->handler_flags == Alter_inplace_info::DROP_INDEX || if (only_flags(ha_alter_info->handler_flags, Alter_inplace_info::DROP_INDEX + Alter_inplace_info::DROP_UNIQUE_INDEX)) {
ha_alter_info->handler_flags == Alter_inplace_info::DROP_UNIQUE_INDEX) { // && tables_have_same_keys TODO???
assert(ha_alter_info->index_add_count == 0); assert(ha_alter_info->index_add_count == 0);
result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK;; result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK;;
} else } else
// add column (and nothing else) // add column (and nothing else)
if (ha_alter_info->handler_flags == Alter_inplace_info::ADD_COLUMN || if (only_flags(ha_alter_info->handler_flags, Alter_inplace_info::ADD_COLUMN + Alter_inplace_info::ALTER_COLUMN_ORDER)) {
ha_alter_info->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 added_columns[altered_table->s->fields];
u_int32_t num_added_columns = 0; u_int32_t num_added_columns = 0;
int r = find_changed_columns(added_columns, &num_added_columns, table, altered_table); int r = find_changed_columns(added_columns, &num_added_columns, table, altered_table);
...@@ -784,8 +782,7 @@ ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_ ...@@ -784,8 +782,7 @@ ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_
} }
} else } else
// drop column (and nothing else) // drop column (and nothing else)
if (ha_alter_info->handler_flags == Alter_inplace_info::DROP_COLUMN || if (only_flags(ha_alter_info->handler_flags, Alter_inplace_info::DROP_COLUMN + Alter_inplace_info::ALTER_COLUMN_ORDER)) {
ha_alter_info->handler_flags == Alter_inplace_info::DROP_COLUMN + Alter_inplace_info::ALTER_COLUMN_ORDER) {
u_int32_t dropped_columns[table->s->fields]; u_int32_t dropped_columns[table->s->fields];
u_int32_t num_dropped_columns = 0; u_int32_t num_dropped_columns = 0;
int r = find_changed_columns(dropped_columns, &num_dropped_columns, altered_table, table); int r = find_changed_columns(dropped_columns, &num_dropped_columns, altered_table, table);
...@@ -828,12 +825,10 @@ ha_tokudb::inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alte ...@@ -828,12 +825,10 @@ ha_tokudb::inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alte
int error = 0; int error = 0;
HA_CREATE_INFO *create_info = ha_alter_info->create_info; HA_CREATE_INFO *create_info = ha_alter_info->create_info;
if (ha_alter_info->handler_flags == Alter_inplace_info::ADD_INDEX || if (ha_alter_info->handler_flags & (Alter_inplace_info::ADD_INDEX + Alter_inplace_info::ADD_UNIQUE_INDEX)) {
ha_alter_info->handler_flags == Alter_inplace_info::ADD_UNIQUE_INDEX) {
error = alter_table_add_index(altered_table, ha_alter_info); error = alter_table_add_index(altered_table, ha_alter_info);
} else } else
if (ha_alter_info->handler_flags == Alter_inplace_info::DROP_INDEX || if (ha_alter_info->handler_flags & (Alter_inplace_info::DROP_INDEX + Alter_inplace_info::DROP_UNIQUE_INDEX)) {
ha_alter_info->handler_flags == Alter_inplace_info::DROP_UNIQUE_INDEX) {
error = alter_table_drop_index(altered_table, ha_alter_info); error = alter_table_drop_index(altered_table, ha_alter_info);
} else } else
if (ha_alter_info->handler_flags & Alter_inplace_info::ADD_COLUMN) { if (ha_alter_info->handler_flags & Alter_inplace_info::ADD_COLUMN) {
...@@ -842,11 +837,11 @@ ha_tokudb::inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alte ...@@ -842,11 +837,11 @@ ha_tokudb::inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alte
if (ha_alter_info->handler_flags & Alter_inplace_info::DROP_COLUMN) { if (ha_alter_info->handler_flags & Alter_inplace_info::DROP_COLUMN) {
error = alter_table_add_or_drop_column(altered_table, ha_alter_info); error = alter_table_add_or_drop_column(altered_table, ha_alter_info);
} else } else
if (ha_alter_info->handler_flags == Alter_inplace_info::CHANGE_CREATE_OPTION && if ((ha_alter_info->handler_flags & Alter_inplace_info::CHANGE_CREATE_OPTION) &&
create_info->used_fields == HA_CREATE_USED_AUTO) { create_info->used_fields == HA_CREATE_USED_AUTO) {
error = write_auto_inc_create(share->status_block, create_info->auto_increment_value, transaction); error = write_auto_inc_create(share->status_block, create_info->auto_increment_value, transaction);
} else } else
if (ha_alter_info->handler_flags == Alter_inplace_info::CHANGE_CREATE_OPTION && if ((ha_alter_info->handler_flags & Alter_inplace_info::CHANGE_CREATE_OPTION) &&
create_info->used_fields == HA_CREATE_USED_ROW_FORMAT) { create_info->used_fields == HA_CREATE_USED_ROW_FORMAT) {
enum toku_compression_method method = TOKU_NO_COMPRESSION; enum toku_compression_method method = TOKU_NO_COMPRESSION;
...@@ -1075,14 +1070,12 @@ ha_tokudb::commit_inplace_alter_table(TABLE *altered_table, Alter_inplace_info * ...@@ -1075,14 +1070,12 @@ ha_tokudb::commit_inplace_alter_table(TABLE *altered_table, Alter_inplace_info *
} }
if (!commit || result == true) { if (!commit || result == true) {
if (ha_alter_info->handler_flags == Alter_inplace_info::ADD_INDEX || if (ha_alter_info->handler_flags & (Alter_inplace_info::ADD_INDEX + Alter_inplace_info::ADD_UNIQUE_INDEX)) {
ha_alter_info->handler_flags == Alter_inplace_info::ADD_UNIQUE_INDEX) {
ha_tokudb_add_index_ctx *ctx = static_cast<ha_tokudb_add_index_ctx *>(ha_alter_info->handler_ctx); ha_tokudb_add_index_ctx *ctx = static_cast<ha_tokudb_add_index_ctx *>(ha_alter_info->handler_ctx);
assert(ctx); assert(ctx);
restore_add_index(table, ha_alter_info->index_add_count, ctx->incremented_num_DBs, ctx->modified_DBs); restore_add_index(table, ha_alter_info->index_add_count, ctx->incremented_num_DBs, ctx->modified_DBs);
} else } else
if (ha_alter_info->handler_flags == Alter_inplace_info::DROP_INDEX || if (ha_alter_info->handler_flags & (Alter_inplace_info::DROP_INDEX + Alter_inplace_info::DROP_UNIQUE_INDEX)) {
ha_alter_info->handler_flags == Alter_inplace_info::DROP_UNIQUE_INDEX) {
// translate KEY pointers to indexes into the key_info array // translate KEY pointers to indexes into the key_info array
uint index_drop_offsets[ha_alter_info->index_drop_count]; uint index_drop_offsets[ha_alter_info->index_drop_count];
for (uint i = 0; i < ha_alter_info->index_drop_count; i++) for (uint i = 0; i < ha_alter_info->index_drop_count; i++)
......
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