diff --git a/sql/server_component/table_access_service.cc b/sql/server_component/table_access_service.cc index 07637443762..cb3a4d57bcf 100644 --- a/sql/server_component/table_access_service.cc +++ b/sql/server_component/table_access_service.cc @@ -39,6 +39,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "sql/table.h" #include "sql/transaction.h" #include "thr_lock.h" +#include "sql/sql_show.h" +#include "sql/sql_tmp_table.h" /* clang-format off */ /** @@ -728,6 +730,8 @@ size_t Table_access_impl::add_table(const char *schema_name, current->next_global = nullptr; current->open_type = OT_BASE_ONLY; // TODO: VIEWS ? current->open_strategy = Table_ref::OPEN_IF_EXISTS; + current->schema_table = find_schema_table(current_thd, state->m_table_name); + current_thd->init_cost_model(); if (m_current_count > 0) { Table_ref *prev = &m_table_array[m_current_count - 1]; @@ -761,6 +765,11 @@ int Table_access_impl::begin() { return TA_ERROR_OPEN; } + // TODO: need to do it for all tables in array + if (m_table_array[0].schema_table) { + do_fill_information_schema_table(current_thd, &(m_table_array[0]), nullptr); + } + assert(!m_in_tx); m_in_tx = true; return 0; @@ -785,6 +794,15 @@ int Table_access_impl::commit() { if (trans_commit_stmt(m_child_thd)) { return 1; } + + // TODO: need to do it for all tables in m_table_array + Table_ref* tl = &(m_table_array[0]); + if (tl->schema_table) { + close_tmp_table(tl->table); + free_tmp_table(tl->table); // Schema tables are per execution + tl->table = nullptr; + } + return 0; } diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 3ab57848aa2..61e66968cfb 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -5269,9 +5269,10 @@ static TABLE *create_schema_table(THD *thd, Table_ref *table_list) { tmp_table_param->func_count = field_count; tmp_table_param->schema_table = true; Query_block *query_block = thd->lex->current_query_block(); + ulonglong active_options = query_block ? query_block->active_options() : 0; if (!(table = create_tmp_table( thd, tmp_table_param, fields, /*group=*/nullptr, false, false, - query_block->active_options() | TMP_TABLE_ALL_COLUMNS, HA_POS_ERROR, + active_options | TMP_TABLE_ALL_COLUMNS, HA_POS_ERROR, table_list->alias))) return nullptr; @@ -5375,7 +5376,7 @@ bool mysql_schema_table(THD *thd, LEX *lex, Table_ref *table_list) { table_alias_charset, table_list->table_name, table_list->alias); table_list->table = table; table->pos_in_table_list = table_list; - if (table_list->query_block->first_execution) + if (table_list->query_block && table_list->query_block->first_execution) table_list->query_block->add_base_options(OPTION_SCHEMA_TABLE); lex->safe_to_cache_query = false;