diff options
author | Sergei Golubchik <serg@mariadb.org> | 2019-01-03 13:09:41 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2019-01-03 13:09:41 +0100 |
commit | 6bb11efa4a7ba813eb4aa2548f95b7297d70f3d7 (patch) | |
tree | 3c2dfb2dfbbb0a2471bdcfb0f0c122f823cc80ab /sql/temporary_tables.cc | |
parent | ab4bc8442094a2be8cdb74bfcddfccede81ac03d (diff) | |
parent | 842402e4df35c230e7a416ce3ef8df3055f03d60 (diff) | |
download | mariadb-git-6bb11efa4a7ba813eb4aa2548f95b7297d70f3d7.tar.gz |
Merge branch '10.2' into 10.3
Diffstat (limited to 'sql/temporary_tables.cc')
-rw-r--r-- | sql/temporary_tables.cc | 50 |
1 files changed, 18 insertions, 32 deletions
diff --git a/sql/temporary_tables.cc b/sql/temporary_tables.cc index 1c8af5eaf66..917a85e6c3b 100644 --- a/sql/temporary_tables.cc +++ b/sql/temporary_tables.cc @@ -1041,39 +1041,28 @@ TABLE *THD::find_temporary_table(const char *key, uint key_length, /* A matching TMP_TABLE_SHARE is found. */ All_share_tables_list::Iterator tables_it(share->all_tmp_tables); - while ((table= tables_it++)) + bool found= false; + while (!found && (table= tables_it++)) { switch (state) { - case TMP_TABLE_IN_USE: - if (table->query_id > 0) - { - result= table; - goto done; - } - break; - case TMP_TABLE_NOT_IN_USE: - if (table->query_id == 0) - { - result= table; - goto done; - } - break; - case TMP_TABLE_ANY: - { - result= table; - goto done; - } - break; - default: /* Invalid */ - DBUG_ASSERT(0); - goto done; + case TMP_TABLE_IN_USE: found= table->query_id > 0; break; + case TMP_TABLE_NOT_IN_USE: found= table->query_id == 0; break; + case TMP_TABLE_ANY: found= true; break; } } + if (table && unlikely(table->m_needs_reopen)) + { + share->all_tmp_tables.remove(table); + free_temporary_table(table); + it.rewind(); + continue; + } + result= table; + break; } } -done: if (locked) { DBUG_ASSERT(m_tmp_tables_locked); @@ -1154,8 +1143,7 @@ TABLE *THD::open_temporary_table(TMP_TABLE_SHARE *share, @return Success false Failure true */ -bool THD::find_and_use_tmp_table(const TABLE_LIST *tl, - TABLE **out_table) +bool THD::find_and_use_tmp_table(const TABLE_LIST *tl, TABLE **out_table) { DBUG_ENTER("THD::find_and_use_tmp_table"); @@ -1165,11 +1153,9 @@ bool THD::find_and_use_tmp_table(const TABLE_LIST *tl, key_length= create_tmp_table_def_key(key, tl->get_db_name(), tl->get_table_name()); - result= - use_temporary_table(find_temporary_table(key, key_length, - TMP_TABLE_NOT_IN_USE), - out_table); - + result= use_temporary_table(find_temporary_table(key, key_length, + TMP_TABLE_NOT_IN_USE), + out_table); DBUG_RETURN(result); } |