From cce2b45c8f5b3245d2e63d2763aeec59153d2c6f Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Thu, 10 Jan 2019 16:32:56 +0200 Subject: MDEV-17803 Row-based event is not applied when table map id is greater 32 bit int Row-based slave applier could not parse correctly the table id when the value exceeded the max of 32 bit unsigned int. The reason turns out in that the being parsed value placeholder was sized as 4 bytes. The type is fixed to ulonglong. Additionally the patch works around Rows_log_event::m_table_id 4 bytes size on 32 bits platforms. In case of last_table_id value overflows the 4 byte max, there won't be the zero value for m_table_id generated and the first wrapped-around value is one, this is thanks to excluding UINT_MAX32 + 1 from TABLE_SHARE::table_map_id. --- sql/table.h | 2 +- sql/table_cache.cc | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'sql') diff --git a/sql/table.h b/sql/table.h index 4a1552f8c0d..10c1d1bc68e 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1816,7 +1816,7 @@ struct TABLE_LIST /* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */ List *index_hints; TABLE *table; /* opened table */ - uint table_id; /* table id (from binlog) for opened table */ + ulonglong table_id; /* table id (from binlog) for opened table */ /* select_result for derived table to pass it from table creation to table filling procedure diff --git a/sql/table_cache.cc b/sql/table_cache.cc index f13d7183a99..1154017d8d5 100644 --- a/sql/table_cache.cc +++ b/sql/table_cache.cc @@ -1206,6 +1206,9 @@ void tdc_assign_new_table_id(TABLE_SHARE *share) DBUG_ASSERT(share); DBUG_ASSERT(tdc_inited); + DBUG_EXECUTE_IF("simulate_big_table_id", + if (last_table_id < UINT_MAX32) + last_table_id= UINT_MAX32 - 1;); /* There is one reserved number that cannot be used. Remember to change this when 6-byte global table id's are introduced. @@ -1215,7 +1218,7 @@ void tdc_assign_new_table_id(TABLE_SHARE *share) my_atomic_rwlock_wrlock(&LOCK_tdc_atomics); tid= my_atomic_add64(&last_table_id, 1); my_atomic_rwlock_wrunlock(&LOCK_tdc_atomics); - } while (unlikely(tid == ~0UL)); + } while (unlikely(tid == ~0UL || tid == 0)); share->table_map_id= tid; DBUG_PRINT("info", ("table_id= %lu", share->table_map_id)); -- cgit v1.2.1 From a0f3b9f94f3094ccb9ce75c53b25d36c4c78e922 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Thu, 24 Jan 2019 13:52:51 +0530 Subject: MDEV-17376 Server fails to set ADD_PK_INDEX, DROP_PK_INDEX if unique index nominated as PK Problem: ======== Server fails to notify the engine by not setting the ADD_PK_INDEX and DROP_PK_INDEX When there is a i) Change in candidate for primary key. ii) New candidate for primary key. Fix: ==== Server sets the ADD_PK_INDEX and DROP_PK_INDEX while doing alter for the above problematic case. --- sql/sql_table.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'sql') diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 2302026b18b..df1ff8eaf5d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -6439,6 +6439,12 @@ static bool fill_alter_inplace_info(THD *thd, KEY *new_key; KEY *new_key_end= ha_alter_info->key_info_buffer + ha_alter_info->key_count; + /* + Primary key index for the new table + */ + const KEY* const new_pk= (ha_alter_info->key_count > 0 && + is_candidate_key(ha_alter_info->key_info_buffer)) ? + ha_alter_info->key_info_buffer : NULL; DBUG_PRINT("info", ("index count old: %d new: %d", table->s->keys, ha_alter_info->key_count)); @@ -6513,6 +6519,17 @@ static bool fill_alter_inplace_info(THD *thd, new_field->field->field_index != key_part->fieldnr - 1) goto index_changed; } + + /* + Rebuild the index if following condition get satisfied: + + (i) Old table doesn't have primary key, new table has it and vice-versa + (ii) Primary key changed to another existing index + */ + if ((new_key == new_pk) != + ((uint) (table_key - table->key_info) == table->s->primary_key)) + goto index_changed; + continue; index_changed: -- cgit v1.2.1