Commit 5ced96de authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

#4505 implement hot alter table auto increment in mysql 5.6

git-svn-id: file:///svn/mysql/tokudb-engine/tokudb-engine@44944 c7de825b-a66e-492c-adef-691d508d4ae1
parent 215fb0e1
...@@ -6,9 +6,20 @@ ...@@ -6,9 +6,20 @@
#endif #endif
#if 50600 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699 #if 50600 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699
#define TOKU_INCLUDE_ALTER_56 1
#define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 0 #define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 0
#define TOKU_INCLUDE_XA 1 #define TOKU_INCLUDE_XA 1
#else #endif
#if 50500 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50599
#define TOKU_INCLUDE_ALTER_56 0
#define TOKU_INCLUDE_ALTER_55 1
#define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 1
#define TOKU_INCLUDE_XA 1
#endif
#if MYSQL_VERSION_ID < 50500
#define TOKU_INCLUDE_ALTER_51 1
#define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 1 #define TOKU_INCLUDE_ROW_TYPE_COMPRESSION 1
#define TOKU_INCLUDE_XA 1 #define TOKU_INCLUDE_XA 1
#endif #endif
...@@ -540,7 +551,7 @@ public: ...@@ -540,7 +551,7 @@ public:
int cmp_ref(const uchar * ref1, const uchar * ref2); int cmp_ref(const uchar * ref1, const uchar * ref2);
bool check_if_incompatible_data(HA_CREATE_INFO * info, uint table_changes); bool check_if_incompatible_data(HA_CREATE_INFO * info, uint table_changes);
#if 50600 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699 #if TOKU_INCLUDE_ALTER_56
public: public:
enum_alter_inplace_result check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_info *ha_alter_info); enum_alter_inplace_result check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_info *ha_alter_info);
bool prepare_inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alter_info); bool prepare_inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alter_info);
...@@ -552,7 +563,8 @@ public: ...@@ -552,7 +563,8 @@ public:
int alter_table_add_or_drop_column(TABLE *altered_table, Alter_inplace_info *ha_alter_info); int alter_table_add_or_drop_column(TABLE *altered_table, Alter_inplace_info *ha_alter_info);
void print_alter_info(TABLE *altered_table, Alter_inplace_info *ha_alter_info); void print_alter_info(TABLE *altered_table, Alter_inplace_info *ha_alter_info);
public: public:
#elif 50500 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50599 #endif
#if TOKU_INCLUDE_ALTER_55
public: public:
int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys, handler_add_index **add); int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys, handler_add_index **add);
int final_add_index(handler_add_index *add, bool commit); int final_add_index(handler_add_index *add, bool commit);
...@@ -562,7 +574,8 @@ public: ...@@ -562,7 +574,8 @@ public:
bool is_alter_table_hot(); bool is_alter_table_hot();
void prepare_for_alter(); void prepare_for_alter();
int new_alter_table_frm_data(const uchar *frm_data, size_t frm_len); int new_alter_table_frm_data(const uchar *frm_data, size_t frm_len);
#else #endif
#if TOKU_INCLUDE_ALTER_51
public: public:
int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys); int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys);
int prepare_drop_index(TABLE *table_arg, uint *key_num, uint num_of_keys); int prepare_drop_index(TABLE *table_arg, uint *key_num, uint num_of_keys);
......
#if MYSQL_VERSION_ID < 50500 #if TOKU_INCLUDE_ALTER_51
volatile int ha_tokudb_add_index_wait = 0; volatile int ha_tokudb_add_index_wait = 0;
......
#if 50500 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50599 #if TOKU_INCLUDE_ALTER_55
class ha_tokudb_add_index : public handler_add_index { class ha_tokudb_add_index : public handler_add_index {
public: public:
......
#if 50600 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699 #if TOKU_INCLUDE_ALTER_56
static bool static bool
tables_have_same_keys(TABLE* table, TABLE* altered_table, bool print_error, bool check_field_index) { tables_have_same_keys(TABLE* table, TABLE* altered_table, bool print_error, bool check_field_index) {
...@@ -727,7 +727,15 @@ ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_ ...@@ -727,7 +727,15 @@ 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
// add index // alter auto_increment (and nothing else)
if (ha_alter_info->handler_flags == Alter_inplace_info::CHANGE_CREATE_OPTION && ha_alter_info->create_info->used_fields == HA_CREATE_USED_AUTO) {
result = HA_ALTER_INPLACE_NO_LOCK;
} else
// alter row_format (and nothing else)
if (ha_alter_info->handler_flags == Alter_inplace_info::CHANGE_CREATE_OPTION && ha_alter_info->create_info->used_fields == HA_CREATE_USED_ROW_FORMAT) {
result = HA_ALTER_INPLACE_NO_LOCK;
} else
// add index (and nothing else)
if (ha_alter_info->handler_flags == Alter_inplace_info::ADD_INDEX || if (ha_alter_info->handler_flags == Alter_inplace_info::ADD_INDEX ||
ha_alter_info->handler_flags == Alter_inplace_info::ADD_UNIQUE_INDEX) { // && tables_have_same_keys TODO??? 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);
...@@ -736,13 +744,13 @@ ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_ ...@@ -736,13 +744,13 @@ ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_
if (get_create_index_online(thd) && ha_alter_info->index_add_count == 1 && thd_sql_command(thd) == SQLCOM_CREATE_INDEX) 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_AFTER_PREPARE; result = HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE;
} else } else
// drop index // drop index (and nothing else)
if (ha_alter_info->handler_flags == Alter_inplace_info::DROP_INDEX || if (ha_alter_info->handler_flags == Alter_inplace_info::DROP_INDEX ||
ha_alter_info->handler_flags == Alter_inplace_info::DROP_UNIQUE_INDEX) { // && tables_have_same_keys TODO??? 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 // add column (and nothing else)
if (ha_alter_info->handler_flags == Alter_inplace_info::ADD_COLUMN || if (ha_alter_info->handler_flags == Alter_inplace_info::ADD_COLUMN ||
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];
...@@ -759,7 +767,7 @@ ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_ ...@@ -759,7 +767,7 @@ ha_tokudb::check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_
result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK; result = HA_ALTER_INPLACE_EXCLUSIVE_LOCK;
} }
} else } else
// drop column // drop column (and nothing else)
if (ha_alter_info->handler_flags == Alter_inplace_info::DROP_COLUMN || if (ha_alter_info->handler_flags == Alter_inplace_info::DROP_COLUMN ||
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];
...@@ -811,6 +819,17 @@ ha_tokudb::inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alte ...@@ -811,6 +819,17 @@ ha_tokudb::inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alte
if (ha_alter_info->handler_flags & Alter_inplace_info::ADD_COLUMN || if (ha_alter_info->handler_flags & Alter_inplace_info::ADD_COLUMN ||
ha_alter_info->handler_flags & Alter_inplace_info::DROP_COLUMN) { 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
if (ha_alter_info->handler_flags == Alter_inplace_info::CHANGE_CREATE_OPTION) {
HA_CREATE_INFO *create_info = ha_alter_info->create_info;
if (create_info->used_fields == HA_CREATE_USED_AUTO) {
error = write_auto_inc_create(share->status_block, create_info->auto_increment_value, transaction);
}
if (create_info->used_fields == HA_CREATE_USED_ROW_FORMAT) {
// TODO handle new row format
printf("TODO row_type=%u\n", (unsigned)create_info->row_type);
error = EAGAIN; // DEBUG
}
} }
bool result = false; // success bool result = false; // success
......
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