summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2020-05-05 15:35:58 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2020-05-05 15:35:58 +0530
commit06b245f76822d6c857877339a02a99aaded4940f (patch)
treeab3cfbcb92e86495954253e0b9d301806ee3fba8
parentb9f177f66ae89d38dc635d2eb35e5db3522cb0c3 (diff)
downloadmariadb-git-06b245f76822d6c857877339a02a99aaded4940f.tar.gz
MDEV-13266: Race condition in ANALYZE TABLE / statistics collection
Fixing a race condition while collecting the engine independent statistics. Thread1> 1) start running "ANALYZE TABLE t PERISTENT FOR COLUMNS (..) INDEXES ($list)" 2) Walk through $list and save it in TABLE::keys_in_use_for_query 3) Close/re-open tables Thread2> 1) Make some use of table t. This involves taking table t from the table cache, and putting it back (with TABLE::keys_in_use_for_query reset to 0) Thread1> continue collecting EITS stats. Since TABLE::keys_in_use_for_query is set to 0 we will not collect statistics for indexes in $list.
-rw-r--r--sql/sql_admin.cc46
1 files changed, 21 insertions, 25 deletions
diff --git a/sql/sql_admin.cc b/sql/sql_admin.cc
index ab95fdc340c..0613495f202 100644
--- a/sql/sql_admin.cc
+++ b/sql/sql_admin.cc
@@ -769,31 +769,6 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
(table->table->s->table_category == TABLE_CATEGORY_USER &&
(get_use_stat_tables_mode(thd) > NEVER ||
lex->with_persistent_for_clause));
-
-
- if (!lex->index_list)
- {
- tab->keys_in_use_for_query.init(tab->s->keys);
- }
- else
- {
- int pos;
- LEX_STRING *index_name;
- List_iterator_fast<LEX_STRING> it(*lex->index_list);
-
- tab->keys_in_use_for_query.clear_all();
- while ((index_name= it++))
- {
- if (tab->s->keynames.type_names == 0 ||
- (pos= find_type(&tab->s->keynames, index_name->str,
- index_name->length, 1)) <= 0)
- {
- compl_result_code= result_code= HA_ADMIN_INVALID;
- break;
- }
- tab->keys_in_use_for_query.set_bit(--pos);
- }
- }
}
if (result_code == HA_ADMIN_OK)
@@ -878,6 +853,27 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
}
tab->file->column_bitmaps_signal();
}
+ if (!lex->index_list)
+ tab->keys_in_use_for_query.init(tab->s->keys);
+ else
+ {
+ int pos;
+ LEX_STRING *index_name;
+ List_iterator_fast<LEX_STRING> it(*lex->index_list);
+
+ tab->keys_in_use_for_query.clear_all();
+ while ((index_name= it++))
+ {
+ if (tab->s->keynames.type_names == 0 ||
+ (pos= find_type(&tab->s->keynames, index_name->str,
+ index_name->length, 1)) <= 0)
+ {
+ compl_result_code= result_code= HA_ADMIN_INVALID;
+ break;
+ }
+ tab->keys_in_use_for_query.set_bit(--pos);
+ }
+ }
if (!(compl_result_code=
alloc_statistics_for_table(thd, table->table)) &&
!(compl_result_code=