Skip to content

Commit 3d90143

Browse files
committed
MDEV-31559 btr_search_hash_table_validate() does not check if CHECK TABLE is killed
btr_search_hash_table_validate(), btr_search_validate(): Add the parameter THD for checking if the statement has been killed. Any non-QUICK CHECK TABLE will validate the entire adaptive hash index for all InnoDB tables, which may be extremely slow when running multiple concurrent CHECK TABLE.
1 parent 6d91121 commit 3d90143

File tree

3 files changed

+31
-34
lines changed

3 files changed

+31
-34
lines changed

storage/innobase/btr/btr0sea.cc

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,24 +2116,29 @@ static bool ha_validate(const hash_table_t *table,
21162116
}
21172117

21182118
/** Validates the search system for given hash table.
2119-
@param[in] hash_table_id hash table to validate
2120-
@return TRUE if ok */
2121-
static
2122-
ibool
2123-
btr_search_hash_table_validate(ulint hash_table_id)
2119+
@param thd connection, for checking if CHECK TABLE has been killed
2120+
@param hash_table_id hash table to validate
2121+
@return true if ok */
2122+
static bool btr_search_hash_table_validate(THD *thd, ulint hash_table_id)
21242123
{
21252124
ha_node_t* node;
2126-
ibool ok = TRUE;
2125+
bool ok = true;
21272126
ulint i;
21282127
ulint cell_count;
21292128
mem_heap_t* heap = NULL;
21302129
rec_offs offsets_[REC_OFFS_NORMAL_SIZE];
21312130
rec_offs* offsets = offsets_;
21322131

21332132
btr_search_x_lock_all();
2134-
if (!btr_search_enabled) {
2133+
if (!btr_search_enabled || (thd && thd_kill_level(thd))) {
2134+
func_exit:
21352135
btr_search_x_unlock_all();
2136-
return(TRUE);
2136+
2137+
if (UNIV_LIKELY_NULL(heap)) {
2138+
mem_heap_free(heap);
2139+
}
2140+
2141+
return ok;
21372142
}
21382143

21392144
/* How many cells to check before temporarily releasing
@@ -2160,8 +2165,8 @@ btr_search_hash_table_validate(ulint hash_table_id)
21602165

21612166
btr_search_x_lock_all();
21622167

2163-
if (!btr_search_enabled) {
2164-
ok = true;
2168+
if (!btr_search_enabled
2169+
|| (thd && thd_kill_level(thd))) {
21652170
goto func_exit;
21662171
}
21672172

@@ -2268,8 +2273,8 @@ btr_search_hash_table_validate(ulint hash_table_id)
22682273

22692274
btr_search_x_lock_all();
22702275

2271-
if (!btr_search_enabled) {
2272-
ok = true;
2276+
if (!btr_search_enabled
2277+
|| (thd && thd_kill_level(thd))) {
22732278
goto func_exit;
22742279
}
22752280

@@ -2290,33 +2295,23 @@ btr_search_hash_table_validate(ulint hash_table_id)
22902295
ulint end_index = ut_min(i + chunk_size - 1, cell_count - 1);
22912296

22922297
if (!ha_validate(&part.table, i, end_index)) {
2293-
ok = FALSE;
2298+
ok = false;
22942299
}
22952300
}
22962301

22972302
mysql_mutex_unlock(&buf_pool.mutex);
2298-
func_exit:
2299-
btr_search_x_unlock_all();
2300-
2301-
if (UNIV_LIKELY_NULL(heap)) {
2302-
mem_heap_free(heap);
2303-
}
2304-
2305-
return(ok);
2303+
goto func_exit;
23062304
}
23072305

2308-
/** Validate the search system.
2309-
@return true if ok. */
2310-
bool
2311-
btr_search_validate()
2306+
/** Validates the search system.
2307+
@param thd connection, for checking if CHECK TABLE has been killed
2308+
@return true if ok */
2309+
bool btr_search_validate(THD *thd)
23122310
{
2313-
for (ulint i = 0; i < btr_ahi_parts; ++i) {
2314-
if (!btr_search_hash_table_validate(i)) {
2315-
return(false);
2316-
}
2317-
}
2318-
2319-
return(true);
2311+
for (ulint i= 0; i < btr_ahi_parts; ++i)
2312+
if (!btr_search_hash_table_validate(thd, i))
2313+
return(false);
2314+
return true;
23202315
}
23212316

23222317
#ifdef UNIV_DEBUG

storage/innobase/handler/ha_innodb.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15406,7 +15406,8 @@ ha_innobase::check(
1540615406
/* We validate the whole adaptive hash index for all tables
1540715407
at every CHECK TABLE only when QUICK flag is not present. */
1540815408

15409-
if (!(check_opt->flags & T_QUICK) && !btr_search_validate()) {
15409+
if (!(check_opt->flags & T_QUICK)
15410+
&& !btr_search_validate(m_prebuilt->trx->mysql_thd)) {
1541015411
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
1541115412
ER_NOT_KEYFILE,
1541215413
"InnoDB: The adaptive hash index is corrupted.");

storage/innobase/include/btr0sea.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ void btr_search_update_hash_on_insert(btr_cur_t *cursor,
127127
void btr_search_update_hash_on_delete(btr_cur_t *cursor);
128128

129129
/** Validates the search system.
130+
@param thd connection, for checking if CHECK TABLE has been killed
130131
@return true if ok */
131-
bool btr_search_validate();
132+
bool btr_search_validate(THD *thd);
132133

133134
/** Lock all search latches in exclusive mode. */
134135
static inline void btr_search_x_lock_all();

0 commit comments

Comments
 (0)