diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index 21b51f2410b..4ceeec9205e 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -101,16 +101,16 @@ operations by purge as the previous, when it seems to be growing huge. throughput clearly from about 100000. */ #define BTR_CUR_FINE_HISTORY_LENGTH 100000 +#ifdef BTR_CUR_HASH_ADAPT /** Number of searches down the B-tree in btr_cur_search_to_nth_level(). */ -Atomic_counter btr_cur_n_non_sea; +ib_counter_t btr_cur_n_non_sea; /** Old value of btr_cur_n_non_sea. Copied by srv_refresh_innodb_monitor_stats(). Referenced by srv_printf_innodb_monitor(). */ ulint btr_cur_n_non_sea_old; -#ifdef BTR_CUR_HASH_ADAPT /** Number of successful adaptive hash index lookups in btr_cur_search_to_nth_level(). */ -ulint btr_cur_n_sea; +ib_counter_t btr_cur_n_sea; /** Old value of btr_cur_n_sea. Copied by srv_refresh_innodb_monitor_stats(). Referenced by srv_printf_innodb_monitor(). */ @@ -1403,7 +1403,8 @@ btr_cur_search_to_nth_level_func( # ifdef UNIV_SEARCH_PERF_STAT info->n_searches++; # endif - if (autoinc == 0 + if (!btr_search_enabled) { + } else if (autoinc == 0 && !estimate && latch_mode <= BTR_MODIFY_LEAF && !modify_external @@ -1429,13 +1430,14 @@ btr_cur_search_to_nth_level_func( || mode != PAGE_CUR_LE); ut_ad(cursor->low_match != ULINT_UNDEFINED || mode != PAGE_CUR_LE); - btr_cur_n_sea++; + ++btr_cur_n_sea; DBUG_RETURN(err); + } else { + ++btr_cur_n_non_sea; } # endif /* BTR_CUR_HASH_ADAPT */ #endif /* BTR_CUR_ADAPT */ - btr_cur_n_non_sea++; /* If the hash search did not succeed, do binary search down the tree */ diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 7199fcfb547..bfb587bef6a 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -889,8 +889,9 @@ static MYSQL_THDVAR_STR(tmpdir, static SHOW_VAR innodb_status_variables[]= { #ifdef BTR_CUR_HASH_ADAPT - {"adaptive_hash_hash_searches", &btr_cur_n_sea, SHOW_SIZE_T}, - {"adaptive_hash_non_hash_searches", &btr_cur_n_non_sea, SHOW_SIZE_T}, + {"adaptive_hash_hash_searches", &export_vars.innodb_ahi_hit, SHOW_SIZE_T}, + {"adaptive_hash_non_hash_searches", + &export_vars.innodb_ahi_miss, SHOW_SIZE_T}, #endif {"background_log_sync", &srv_log_writes_and_flush, SHOW_SIZE_T}, {"buffer_pool_dump_status", diff --git a/storage/innobase/include/btr0cur.h b/storage/innobase/include/btr0cur.h index 966cb73cdbf..6668fb6ca67 100644 --- a/storage/innobase/include/btr0cur.h +++ b/storage/innobase/include/btr0cur.h @@ -969,16 +969,16 @@ earlier version of the row. In rollback we are not allowed to free an inherited external field. */ #define BTR_EXTERN_INHERITED_FLAG 64U +#ifdef BTR_CUR_HASH_ADAPT /** Number of searches down the B-tree in btr_cur_search_to_nth_level(). */ -extern Atomic_counter btr_cur_n_non_sea; +extern ib_counter_t btr_cur_n_non_sea; /** Old value of btr_cur_n_non_sea. Copied by srv_refresh_innodb_monitor_stats(). Referenced by srv_printf_innodb_monitor(). */ extern ulint btr_cur_n_non_sea_old; -#ifdef BTR_CUR_HASH_ADAPT /** Number of successful adaptive hash index lookups in btr_cur_search_to_nth_level(). */ -extern ulint btr_cur_n_sea; +extern ib_counter_t btr_cur_n_sea; /** Old value of btr_cur_n_sea. Copied by srv_refresh_innodb_monitor_stats(). Referenced by srv_printf_innodb_monitor(). */ diff --git a/storage/innobase/include/srv0mon.h b/storage/innobase/include/srv0mon.h index 56b56a18bdb..32da0e4e2b4 100644 --- a/storage/innobase/include/srv0mon.h +++ b/storage/innobase/include/srv0mon.h @@ -345,9 +345,7 @@ enum monitor_id_t { /* Adaptive Hash Index related counters */ MONITOR_MODULE_ADAPTIVE_HASH, MONITOR_OVLD_ADAPTIVE_HASH_SEARCH, -#endif /* BTR_CUR_HASH_ADAPT */ MONITOR_OVLD_ADAPTIVE_HASH_SEARCH_BTREE, -#ifdef BTR_CUR_HASH_ADAPT MONITOR_ADAPTIVE_HASH_PAGE_ADDED, MONITOR_ADAPTIVE_HASH_PAGE_REMOVED, MONITOR_ADAPTIVE_HASH_ROW_ADDED, diff --git a/storage/innobase/include/srv0srv.h b/storage/innobase/include/srv0srv.h index d26a3fe97cc..41a0be0c5ff 100644 --- a/storage/innobase/include/srv0srv.h +++ b/storage/innobase/include/srv0srv.h @@ -697,6 +697,10 @@ void srv_master_thread_enable(); /** Status variables to be passed to MySQL */ struct export_var_t{ +#ifdef BTR_CUR_HASH_ADAPT + ulint innodb_ahi_hit; + ulint innodb_ahi_miss; +#endif /* BTR_CUR_HASH_ADAPT */ char innodb_buffer_pool_dump_status[OS_FILE_MAX_PATH + 128];/*!< Buf pool dump status */ char innodb_buffer_pool_load_status[OS_FILE_MAX_PATH + 128];/*!< Buf pool load status */ char innodb_buffer_pool_resize_status[512];/*!< Buf pool resize status */ diff --git a/storage/innobase/srv/srv0mon.cc b/storage/innobase/srv/srv0mon.cc index cd7e5c526d8..50d9ebff962 100644 --- a/storage/innobase/srv/srv0mon.cc +++ b/storage/innobase/srv/srv0mon.cc @@ -959,7 +959,6 @@ static monitor_info_t innodb_counter_info[] = static_cast( MONITOR_EXISTING | MONITOR_DEFAULT_ON), MONITOR_DEFAULT_START, MONITOR_OVLD_ADAPTIVE_HASH_SEARCH}, -#endif /* BTR_CUR_HASH_ADAPT */ {"adaptive_hash_searches_btree", "adaptive_hash_index", "Number of searches using B-tree on an index search", @@ -967,7 +966,6 @@ static monitor_info_t innodb_counter_info[] = MONITOR_EXISTING | MONITOR_DEFAULT_ON), MONITOR_DEFAULT_START, MONITOR_OVLD_ADAPTIVE_HASH_SEARCH_BTREE}, -#ifdef BTR_CUR_HASH_ADAPT {"adaptive_hash_pages_added", "adaptive_hash_index", "Number of index pages on which the Adaptive Hash Index is built", MONITOR_NONE, @@ -1819,11 +1817,11 @@ srv_mon_process_existing_counter( case MONITOR_OVLD_ADAPTIVE_HASH_SEARCH: value = btr_cur_n_sea; break; -#endif /* BTR_CUR_HASH_ADAPT */ case MONITOR_OVLD_ADAPTIVE_HASH_SEARCH_BTREE: value = btr_cur_n_non_sea; break; +#endif /* BTR_CUR_HASH_ADAPT */ case MONITOR_OVLD_PAGE_COMPRESS_SAVED: value = srv_stats.page_compression_saved; diff --git a/storage/innobase/srv/srv0srv.cc b/storage/innobase/srv/srv0srv.cc index 74da09b605a..1f2b05ecfa4 100644 --- a/storage/innobase/srv/srv0srv.cc +++ b/storage/innobase/srv/srv0srv.cc @@ -699,8 +699,8 @@ static void srv_refresh_innodb_monitor_stats(time_t current_time) #ifdef BTR_CUR_HASH_ADAPT btr_cur_n_sea_old = btr_cur_n_sea; -#endif /* BTR_CUR_HASH_ADAPT */ btr_cur_n_non_sea_old = btr_cur_n_non_sea; +#endif /* BTR_CUR_HASH_ADAPT */ log_refresh_stats(); @@ -839,20 +839,18 @@ srv_printf_innodb_monitor( part->latch.rd_unlock(); } + /* btr_cur_n_sea_old and btr_cur_n_non_sea_old are protected by + srv_innodb_monitor_mutex (srv_refresh_innodb_monitor_stats) */ + const ulint with_ahi = btr_cur_n_sea, without_ahi = btr_cur_n_non_sea; fprintf(file, "%.2f hash searches/s, %.2f non-hash searches/s\n", - static_cast(btr_cur_n_sea - btr_cur_n_sea_old) + static_cast(with_ahi - btr_cur_n_sea_old) / time_elapsed, - static_cast(btr_cur_n_non_sea - btr_cur_n_non_sea_old) - / time_elapsed); - btr_cur_n_sea_old = btr_cur_n_sea; -#else /* BTR_CUR_HASH_ADAPT */ - fprintf(file, - "%.2f non-hash searches/s\n", - static_cast(btr_cur_n_non_sea - btr_cur_n_non_sea_old) + static_cast(without_ahi - btr_cur_n_non_sea_old) / time_elapsed); + btr_cur_n_sea_old = with_ahi; + btr_cur_n_non_sea_old = without_ahi; #endif /* BTR_CUR_HASH_ADAPT */ - btr_cur_n_non_sea_old = btr_cur_n_non_sea; fputs("---\n" "LOG\n" @@ -968,6 +966,9 @@ srv_export_innodb_status(void) } #ifdef BTR_CUR_HASH_ADAPT + export_vars.innodb_ahi_hit = btr_cur_n_sea; + export_vars.innodb_ahi_miss = btr_cur_n_non_sea; + ulint mem_adaptive_hash = 0; for (ulong i = 0; i < btr_ahi_parts; i++) { const auto part= &btr_search_sys.parts[i];