From 4fcb173c41ea85655b78db7839af1a76503f5084 Mon Sep 17 00:00:00 2001 From: Alexander Nozdrin Date: Fri, 27 Aug 2010 12:39:01 +0400 Subject: [PATCH] Bug#27480 (Extend CREATE TEMPORARY TABLES privilege to allow temp table operations) -- prerequisite patch #1. Move a piece of code that initialiazes TABLE instance after it was successfully opened into a separate function. This function will be reused in the following patches. --- sql/sql_base.cc | 36 +++---------------------------- sql/table.cc | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ sql/table.h | 1 + 3 files changed, 61 insertions(+), 33 deletions(-) diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 01ab0b6dec5..c14f2f41809 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -3023,41 +3023,11 @@ retry_share: table->reginfo.lock_type=TL_READ; /* Assume read */ reset: - DBUG_ASSERT(table->s->ref_count > 0 || table->s->tmp_table != NO_TMP_TABLE); - - if (thd->lex->need_correct_ident()) - table->alias_name_used= my_strcasecmp(table_alias_charset, - table->s->table_name.str, alias); - /* Fix alias if table name changes */ - if (strcmp(table->alias, alias)) - { - uint length=(uint) strlen(alias)+1; - table->alias= (char*) my_realloc((char*) table->alias, length, - MYF(MY_WME)); - memcpy((char*) table->alias, alias, length); - } - table->tablenr=thd->current_tablenr++; - table->used_fields=0; - table->const_table=0; - table->null_row= table->maybe_null= 0; - table->force_index= table->force_index_order= table->force_index_group= 0; - table->status=STATUS_NO_RECORD; - table->insert_values= 0; - table->fulltext_searched= 0; - table->file->ft_handler= 0; - table->reginfo.impossible_range= 0; - /* Catch wrong handling of the auto_increment_field_not_null. */ - DBUG_ASSERT(!table->auto_increment_field_not_null); - table->auto_increment_field_not_null= FALSE; - if (table->timestamp_field) - table->timestamp_field_type= table->timestamp_field->get_auto_set_type(); - table->pos_in_table_list= table_list; table_list->updatable= 1; // It is not derived table nor non-updatable VIEW - table->clear_column_bitmaps(); table_list->table= table; - DBUG_ASSERT(table->key_read == 0); - /* Tables may be reused in a sub statement. */ - DBUG_ASSERT(! table->file->extra(HA_EXTRA_IS_ATTACHED_CHILDREN)); + + table->init(thd, table_list); + DBUG_RETURN(FALSE); err_lock: diff --git a/sql/table.cc b/sql/table.cc index f08a0aa84ca..5cdc0ce9042 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -3223,6 +3223,63 @@ bool TABLE_SHARE::wait_for_old_version(THD *thd, struct timespec *abstime, } +/** + Initialize TABLE instance and prepare it to be used further. + Set the 'alias' attribute from the specified TABLE_LIST element. + Remember the TABLE_LIST element in the 'pos_in_table_list' member. + + @param thd Thread context. + @param tl TABLE_LIST element. +*/ + +void TABLE::init(THD *thd, TABLE_LIST *tl) +{ + DBUG_ASSERT(s->ref_count > 0 || s->tmp_table != NO_TMP_TABLE); + + if (thd->lex->need_correct_ident()) + alias_name_used= my_strcasecmp(table_alias_charset, + s->table_name.str, + tl->alias); + /* Fix alias if table name changes. */ + if (strcmp(alias, tl->alias)) + { + uint length= (uint) strlen(tl->alias)+1; + alias= (char*) my_realloc((char*) alias, length, MYF(MY_WME)); + memcpy((char*) alias, tl->alias, length); + } + + tablenr= thd->current_tablenr++; + used_fields= 0; + const_table= 0; + null_row= 0; + maybe_null= 0; + force_index= 0; + force_index_order= 0; + force_index_group= 0; + status= STATUS_NO_RECORD; + insert_values= 0; + fulltext_searched= 0; + file->ft_handler= 0; + reginfo.impossible_range= 0; + + /* Catch wrong handling of the auto_increment_field_not_null. */ + DBUG_ASSERT(!auto_increment_field_not_null); + auto_increment_field_not_null= FALSE; + + if (timestamp_field) + timestamp_field_type= timestamp_field->get_auto_set_type(); + + pos_in_table_list= tl; + + clear_column_bitmaps(); + + DBUG_ASSERT(key_read == 0); + + /* Tables may be reused in a sub statement. */ + DBUG_ASSERT(!file->extra(HA_EXTRA_IS_ATTACHED_CHILDREN)); +} + + /* Create Item_field for each column in the table. diff --git a/sql/table.h b/sql/table.h index bce1124fbb3..aa177c99856 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1097,6 +1097,7 @@ public: #endif MDL_ticket *mdl_ticket; + void init(THD *thd, TABLE_LIST *tl); bool fill_item_list(List *item_list) const; void reset_item_list(List *item_list) const; void clear_column_bitmaps(void);