Skip to content

Commit

Permalink
MDEV-10682 Race condition between ANALYZE and STATS_AUTO_RECALC
Browse files Browse the repository at this point in the history
ha_innobase::info_low(): While collecting statistics for
ANALYZE TABLE, ensure that dict_stats_process_entry_from_recalc_pool()
is not executing on the same table.

We observed result differences for the test innodb.innodb_stats because
dict_stats_empty_index() was being invoked by the background statistics
calculation while ha_innobase::analyze() was executing
dict_stats_analyze_index_level().
  • Loading branch information
dr-m committed Mar 18, 2021
1 parent 6505662 commit c557e95
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14411,6 +14411,13 @@ ha_innobase::info_low(
if (dict_stats_is_persistent_enabled(ib_table)) {

if (is_analyze) {
row_mysql_lock_data_dictionary(
m_prebuilt->trx);
dict_stats_recalc_pool_del(ib_table);
dict_stats_wait_bg_to_stop_using_table(
ib_table, m_prebuilt->trx);
row_mysql_unlock_data_dictionary(
m_prebuilt->trx);
opt = DICT_STATS_RECALC_PERSISTENT;
} else {
/* This is e.g. 'SHOW INDEXES', fetch
Expand All @@ -14423,6 +14430,13 @@ ha_innobase::info_low(

ret = dict_stats_update(ib_table, opt);

if (opt == DICT_STATS_RECALC_PERSISTENT) {
mutex_enter(&dict_sys->mutex);
ib_table->stats_bg_flag
&= byte(~BG_STAT_SHOULD_QUIT);
mutex_exit(&dict_sys->mutex);
}

if (ret != DB_SUCCESS) {
m_prebuilt->trx->op_info = "";
DBUG_RETURN(HA_ERR_GENERIC);
Expand Down

0 comments on commit c557e95

Please sign in to comment.