diff options
author | unknown <dlenev@mysql.com> | 2006-01-13 01:51:56 +0300 |
---|---|---|
committer | unknown <dlenev@mysql.com> | 2006-01-13 01:51:56 +0300 |
commit | c12a3dfefd29b3bb4a93fee4778e0e94b1e00871 (patch) | |
tree | a73da6b24137a2305db12f95fa6f8e6e37e3b724 /sql/sp_head.cc | |
parent | 8fc4efe657899dbcebb4dbdc907a60ab03200f07 (diff) | |
download | mariadb-git-c12a3dfefd29b3bb4a93fee4778e0e94b1e00871.tar.gz |
Fix for bug #12198 "Temporary table aliasing does not work inside stored
functions".
We should ignore alias when we check if table was already marked as temporary
when we calculate set of tables to be prelocked. Otherwise we will erroneously
treat tables which are used in same routine and have same name but different
alias as non-temporary.
mysql-test/r/sp.result:
Added test for bug #12198 "Temporary table aliasing does not work inside stored
functions" and other tests which cover handling of temporary tables in prelocked
mode.
mysql-test/t/sp.test:
Added test for bug #12198 "Temporary table aliasing does not work inside stored
functions" and other tests which cover handling of temporary tables in prelocked
mode.
sql/sp_head.cc:
sp_head::merge_table_list():
We should ignore alias when we check if table was already marked as temporary
when we calculate set of tables to be prelocked. Otherwise we will erroneously
treat tables which are used in same routine and have same name but different
alias as non-temporary.
Diffstat (limited to 'sql/sp_head.cc')
-rw-r--r-- | sql/sp_head.cc | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/sql/sp_head.cc b/sql/sp_head.cc index a6e88c08789..8d0212a31da 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -2992,7 +2992,14 @@ sp_restore_security_context(THD *thd, Security_context *backup) typedef struct st_sp_table { - LEX_STRING qname; /* Multi-set key: db_name\0table_name\0alias\0 */ + /* + Multi-set key: + db_name\0table_name\0alias\0 - for normal tables + db_name\0table_name\0 - for temporary tables + Note that in both cases we don't take last '\0' into account when + we count length of key. + */ + LEX_STRING qname; uint db_length, table_name_length; bool temp; /* true if corresponds to a temporary table */ thr_lock_type lock_type; /* lock type used for prelocking */ @@ -3062,10 +3069,14 @@ sp_head::merge_table_list(THD *thd, TABLE_LIST *table, LEX *lex_for_tmp_check) tname[tlen]= '\0'; /* - It is safe to store pointer to table list elements in hash, - since they are supposed to have the same lifetime. + We ignore alias when we check if table was already marked as temporary + (and therefore should not be prelocked). Otherwise we will erroneously + treat table with same name but with different alias as non-temporary. */ - if ((tab= (SP_TABLE *)hash_search(&m_sptabs, (byte *)tname, tlen))) + if ((tab= (SP_TABLE *)hash_search(&m_sptabs, (byte *)tname, tlen)) || + ((tab= (SP_TABLE *)hash_search(&m_sptabs, (byte *)tname, + tlen - alen - 1)) && + tab->temp)) { if (tab->lock_type < table->lock_type) tab->lock_type= table->lock_type; // Use the table with the highest lock type @@ -3077,14 +3088,18 @@ sp_head::merge_table_list(THD *thd, TABLE_LIST *table, LEX *lex_for_tmp_check) { if (!(tab= (SP_TABLE *)thd->calloc(sizeof(SP_TABLE)))) return FALSE; - tab->qname.length= tlen; - tab->qname.str= (char*) thd->memdup(tname, tab->qname.length + 1); - if (!tab->qname.str) - return FALSE; if (lex_for_tmp_check->sql_command == SQLCOM_CREATE_TABLE && lex_for_tmp_check->query_tables == table && lex_for_tmp_check->create_info.options & HA_LEX_CREATE_TMP_TABLE) + { tab->temp= TRUE; + tab->qname.length= tlen - alen - 1; + } + else + tab->qname.length= tlen; + tab->qname.str= (char*) thd->memdup(tname, tab->qname.length + 1); + if (!tab->qname.str) + return FALSE; tab->table_name_length= table->table_name_length; tab->db_length= table->db_length; tab->lock_type= table->lock_type; |