diff options
Diffstat (limited to 'sql/temporary_tables.cc')
-rw-r--r-- | sql/temporary_tables.cc | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/sql/temporary_tables.cc b/sql/temporary_tables.cc index 3201b306fad..f23ec7a1acc 100644 --- a/sql/temporary_tables.cc +++ b/sql/temporary_tables.cc @@ -19,6 +19,7 @@ All methods pertaining to temporary tables. */ +#include "mariadb.h" #include "sql_acl.h" /* TMP_TABLE_ACLS */ #include "sql_base.h" /* tdc_create_key */ #include "lock.h" /* mysql_lock_remove */ @@ -64,7 +65,8 @@ TABLE *THD::create_and_open_tmp_table(handlerton *hton, const char *path, const char *db, const char *table_name, - bool open_in_engine) + bool open_in_engine, + bool open_internal_tables) { DBUG_ENTER("THD::create_and_open_tmp_table"); @@ -73,7 +75,9 @@ TABLE *THD::create_and_open_tmp_table(handlerton *hton, if ((share= create_temporary_table(hton, frm, path, db, table_name))) { + open_options|= HA_OPEN_FOR_CREATE; table= open_temporary_table(share, table_name, open_in_engine); + open_options&= ~HA_OPEN_FOR_CREATE; /* Failed to open a temporary table instance. As we are not passing @@ -87,6 +91,15 @@ TABLE *THD::create_and_open_tmp_table(handlerton *hton, /* Free the TMP_TABLE_SHARE. */ free_tmp_table_share(share, false); + DBUG_RETURN(0); + } + + /* Open any related tables */ + if (open_internal_tables && table->internal_tables && + open_and_lock_internal_tables(table, open_in_engine)) + { + drop_temporary_table(table, NULL, false); + DBUG_RETURN(0); } } @@ -248,7 +261,7 @@ TMP_TABLE_SHARE *THD::find_tmp_table_share(const TABLE_LIST *tl) @return Success A pointer to table share object Failure NULL */ -TMP_TABLE_SHARE *THD::find_tmp_table_share(const char *key, uint key_length) +TMP_TABLE_SHARE *THD::find_tmp_table_share(const char *key, size_t key_length) { DBUG_ENTER("THD::find_tmp_table_share"); @@ -313,7 +326,7 @@ TMP_TABLE_SHARE *THD::find_tmp_table_share(const char *key, uint key_length) bool THD::open_temporary_table(TABLE_LIST *tl) { DBUG_ENTER("THD::open_temporary_table"); - DBUG_PRINT("enter", ("table: '%s'.'%s'", tl->db, tl->table_name)); + DBUG_PRINT("enter", ("table: '%s'.'%s'", tl->db.str, tl->table_name.str)); TMP_TABLE_SHARE *share; TABLE *table= NULL; @@ -376,7 +389,7 @@ bool THD::open_temporary_table(TABLE_LIST *tl) if (tl->open_type == OT_TEMPORARY_ONLY && tl->open_strategy == TABLE_LIST::OPEN_NORMAL) { - my_error(ER_NO_SUCH_TABLE, MYF(0), tl->db, tl->table_name); + my_error(ER_NO_SUCH_TABLE, MYF(0), tl->db.str, tl->table_name.str); DBUG_RETURN(true); } DBUG_RETURN(false); @@ -529,25 +542,21 @@ bool THD::close_temporary_tables() true Error */ bool THD::rename_temporary_table(TABLE *table, - const char *db, - const char *table_name) + const LEX_CSTRING *db, + const LEX_CSTRING *table_name) { - DBUG_ENTER("THD::rename_temporary_table"); - char *key; uint key_length; - TABLE_SHARE *share= table->s; + DBUG_ENTER("THD::rename_temporary_table"); if (!(key= (char *) alloc_root(&share->mem_root, MAX_DBKEY_LENGTH))) - { DBUG_RETURN(true); - } /* Temporary tables are renamed by simply changing their table definition key. */ - key_length= create_tmp_table_def_key(key, db, table_name); + key_length= create_tmp_table_def_key(key, db->str, table_name->str); share->set_table_cache_key(key, key_length); DBUG_RETURN(false); @@ -1087,22 +1096,25 @@ done: Failure NULL */ TABLE *THD::open_temporary_table(TMP_TABLE_SHARE *share, - const char *alias, + const char *alias_arg, bool open_in_engine) { + TABLE *table; + LEX_CSTRING alias= {alias_arg, strlen(alias_arg) }; DBUG_ENTER("THD::open_temporary_table"); - TABLE *table; if (!(table= (TABLE *) my_malloc(sizeof(TABLE), MYF(MY_WME)))) { DBUG_RETURN(NULL); /* Out of memory */ } - if (open_table_from_share(this, share, alias, + if (open_table_from_share(this, share, &alias, open_in_engine ? (uint)HA_OPEN_KEYFILE : 0, - EXTRA_RECORD, ha_open_options, table, - open_in_engine ? false : true)) + EXTRA_RECORD, + (ha_open_options | + (open_options & HA_OPEN_FOR_CREATE)), + table, open_in_engine ? false : true)) { my_free(table); DBUG_RETURN(NULL); @@ -1110,8 +1122,9 @@ TABLE *THD::open_temporary_table(TMP_TABLE_SHARE *share, table->reginfo.lock_type= TL_WRITE; /* Simulate locked */ table->grant.privilege= TMP_TABLE_ACLS; - share->tmp_table= (table->file->has_transactions() ? + share->tmp_table= (table->file->has_transaction_manager() ? TRANSACTIONAL_TMP_TABLE : NON_TRANSACTIONAL_TMP_TABLE); + share->not_usable_by_query_cache= 1; table->pos_in_table_list= 0; table->query_id= query_id; @@ -1125,7 +1138,8 @@ TABLE *THD::open_temporary_table(TMP_TABLE_SHARE *share, thread_safe_increment32(&slave_open_temp_tables); } - DBUG_PRINT("tmptable", ("Opened table: '%s'.'%s'%p", table->s->db.str, + DBUG_PRINT("tmptable", ("Opened table: '%s'.'%s table: %p", + table->s->db.str, table->s->table_name.str, table)); DBUG_RETURN(table); } @@ -1361,8 +1375,7 @@ bool THD::log_events_and_free_tmp_shares() We are going to add ` around the table names and possible more due to special characters. */ - append_identifier(this, &s_query, share->table_name.str, - share->table_name.length); + append_identifier(this, &s_query, &share->table_name); s_query.append(','); rm_temporary_table(share->db_type(), share->path.str); free_table_share(share); @@ -1383,7 +1396,8 @@ bool THD::log_events_and_free_tmp_shares() get_stmt_da()->set_overwrite_status(true); transaction.stmt.mark_dropped_temp_table(); - if ((error= (mysql_bin_log.write(&qinfo) || error))) + bool error2= mysql_bin_log.write(&qinfo); + if (unlikely(error|= error2)) { /* If we're here following THD::cleanup, thence the connection |