commit 3dad1aa3ef91761628cbb31d3920c670fd3478c5 Author: Fangxin Lou Date: Sat Mar 7 08:35:19 2020 +0800 [perf] optimize AHI disable logic Add disable_in_progress to disable AHI search and maintain first, and then start to disable AHI. (see btr_search_disable function) diff --git a/storage/innobase/btr/btr0sea.cc b/storage/innobase/btr/btr0sea.cc index 5403a1beec1..32b8d023442 100644 --- a/storage/innobase/btr/btr0sea.cc +++ b/storage/innobase/btr/btr0sea.cc @@ -55,6 +55,7 @@ this program; if not, write to the Free Software Foundation, Inc., /** Is search system enabled. Search system is protected by array of latches. */ bool btr_search_enabled = true; +bool btr_search_disable_in_progress = false; /** Number of adaptive hash index partition. */ ulong btr_ahi_parts = 8; @@ -301,6 +302,10 @@ static void btr_search_disable_ref_count(dict_table_t *table) { void btr_search_disable(bool need_mutex) { dict_table_t *table; + /* set disalbe_in_progress and sleep for a while */ + btr_search_disable_in_progress = true; + os_thread_sleep(100000); + if (need_mutex) { mutex_enter(&dict_sys->mutex); } @@ -313,11 +318,13 @@ void btr_search_disable(bool need_mutex) { mutex_exit(&dict_sys->mutex); } + btr_search_disable_in_progress = false; btr_search_x_unlock_all(); return; } btr_search_enabled = false; + btr_search_disable_in_progress = false; /* Clear the index->search_info->ref_count of every index in the data dictionary cache. */ @@ -874,7 +881,7 @@ ibool btr_search_guess_on_hash(dict_index_t *index, btr_search_t *info, btr_pcur_t pcur; #endif - if (!btr_search_enabled) { + if (!btr_search_enabled || btr_search_disable_in_progress) { return (FALSE); } @@ -1450,7 +1457,8 @@ static void btr_search_build_page_hash_index(dict_index_t *index, ulint offsets_[REC_OFFS_NORMAL_SIZE]; ulint *offsets = offsets_; - if (index->disable_ahi || !btr_search_enabled) { + if (index->disable_ahi || !btr_search_enabled || + btr_search_disable_in_progress) { return; } @@ -1622,7 +1630,8 @@ void btr_search_move_or_delete_hash_entries(buf_block_t *new_block, /* AHI is disabled for intrinsic table as it depends on index-id which is dynamically assigned for intrinsic table indexes and not through a centralized index generator. */ - if (index->disable_ahi || !btr_search_enabled) { + if (index->disable_ahi || !btr_search_enabled || + btr_search_disable_in_progress) { return; } @@ -1684,7 +1693,8 @@ void btr_search_update_hash_on_delete(btr_cur_t *cursor) { mem_heap_t *heap = NULL; rec_offs_init(offsets_); - if (cursor->index->disable_ahi || !btr_search_enabled) { + if (cursor->index->disable_ahi || !btr_search_enabled || + btr_search_disable_in_progress) { return; } @@ -1744,7 +1754,8 @@ void btr_search_update_hash_node_on_insert(btr_cur_t *cursor) { dict_index_t *index; rec_t *rec; - if (cursor->index->disable_ahi || !btr_search_enabled) { + if (cursor->index->disable_ahi || !btr_search_enabled || + btr_search_disable_in_progress) { return; } @@ -1815,7 +1826,8 @@ void btr_search_update_hash_on_insert(btr_cur_t *cursor) { ulint *offsets = offsets_; rec_offs_init(offsets_); - if (cursor->index->disable_ahi || !btr_search_enabled) { + if (cursor->index->disable_ahi || !btr_search_enabled || + btr_search_disable_in_progress) { return; } diff --git a/storage/innobase/include/btr0types.h b/storage/innobase/include/btr0types.h index d1abed66edc..364db9d3385 100644 --- a/storage/innobase/include/btr0types.h +++ b/storage/innobase/include/btr0types.h @@ -50,6 +50,7 @@ struct btr_search_t; /** Is search system enabled. Search system is protected by array of latches. */ extern bool btr_search_enabled; +extern bool btr_search_disable_in_progress; /** Number of adaptive hash index partition. */ extern ulong btr_ahi_parts; diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index c60fd6ae063..79fee6a0dd0 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -4481,6 +4481,7 @@ dberr_t row_search_mvcc(byte *buf, page_cur_mode_t mode, may be long and there may be externally stored fields */ if (UNIV_UNLIKELY(direction == 0) && unique_search && btr_search_enabled && + !btr_search_disable_in_progress && index->is_clustered() && !prebuilt->templ_contains_blob && !prebuilt->used_in_HANDLER && (prebuilt->mysql_row_len < UNIV_PAGE_SIZE / 8) && !prebuilt->innodb_api) {