diff options
author | unknown <kostja@bodhi.(none)> | 2007-07-27 16:37:29 +0400 |
---|---|---|
committer | unknown <kostja@bodhi.(none)> | 2007-07-27 16:37:29 +0400 |
commit | 0936976e8d21a4980145d31657b862652af29f22 (patch) | |
tree | 222b968f3296750c8756393cb2779dcfb1da2784 /sql/sql_base.cc | |
parent | 2612fc43b53a69320ba41011aa632ec35b734211 (diff) | |
download | mariadb-git-0936976e8d21a4980145d31657b862652af29f22.tar.gz |
A fix and a test case for Bug#24918 drop table and lock / inconsistent
between perm and temp tables. Review fixes.
The original bug report complains that if we locked a temporary table
with LOCK TABLES statement, we would not leave LOCK TABLES mode
when this temporary table is dropped.
Additionally, the bug was escalated when it was discovered than
when a temporary transactional table that was previously
locked with LOCK TABLES statement was dropped, futher actions with
this table, such as UNLOCK TABLES, would lead to a crash.
The problem originates from incomplete support of transactional temporary
tables. When we added calls to handler::store_lock()/handler::external_lock()
to operations that work with such tables, we only covered the normal
server code flow and did not cover LOCK TABLES mode.
In LOCK TABLES mode, ::external_lock(LOCK) would sometimes be called without
matching ::external_lock(UNLOCK), e.g. when a transactional temporary table
was dropped. Additionally, this table would be left in the list of LOCKed
TABLES.
The patch aims to address this inadequacy. Now, whenever an instance
of 'handler' is destroyed, we assert that it was priorly
external_lock(UNLOCK)-ed. All the places that violate this assert
were fixed.
This patch introduces no changes in behavior -- the discrepancy in
behavior will be fixed when we start calling ::store_lock()/::external_lock()
for all tables, regardless whether they are transactional or not,
temporary or not.
mysql-test/r/innodb_mysql.result:
Update test results (Bug#24918)
mysql-test/t/innodb_mysql.test:
Add a test case for Bug#24918
sql/handler.h:
Make handler::external_lock() a protected method. Backport from 5.1 its
public wrapper handler::ha_external_lock().
Assert that the handler is not closed if it is still locked.
sql/lock.cc:
In mysql_lock_tables only call lock_external() for the list of tables that
we called store_lock() for.
E.g. get_lock_data() does not add non-transactional temporary tables to the
lock list, so lock_external() should not be called for them.
Use handler::ha_external_lock() instead of handler::external_lock().
Add comments for mysql_lock_remove(), parameterize one strange
side effect that it has. At least in one place where mysql_lock_remove
is used, this side effect is not desired (DROP TABLE). The parameter
will be dropped in 5.1, along with the side effect.
sql/mysql_priv.h:
Update declaration of mysql_lock_remove().
sql/opt_range.cc:
Deploy handler::ha_external_lock() instead of handler::external_lock()
sql/sql_base.cc:
When closing a temporary table, remove the table from the list of LOCKed
TABLES of this thread, in case it's there.
It's there if it is a transactional temporary table.
Use a new declaration of mysql_lock_remove().
sql/sql_class.h:
Extend the comment for THD::temporary_tables.
sql/sql_table.cc:
Deploy handler::ha_external_lock() instead of handler::external_lock()
Diffstat (limited to 'sql/sql_base.cc')
-rw-r--r-- | sql/sql_base.cc | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 3860dfa1ded..61847a6b168 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1037,6 +1037,31 @@ TABLE **find_temporary_table(THD *thd, const char *db, const char *table_name) return 0; // Not a temporary table } + +/** + Drop a temporary table. + + Try to locate the table in the list of thd->temporary_tables. + If the table is found: + - if the table is in thd->locked_tables, unlock it and + remove it from the list of locked tables. Currently only transactional + temporary tables are present in the locked_tables list. + - Close the temporary table, remove its .FRM + - remove the table from the list of temporary tables + + This function is used to drop user temporary tables, as well as + internal tables created in CREATE TEMPORARY TABLE ... SELECT + or ALTER TABLE. Even though part of the work done by this function + is redundant when the table is internal, as long as we + link both internal and user temporary tables into the same + thd->temporary_tables list, it's impossible to tell here whether + we're dealing with an internal or a user temporary table. + + @retval TRUE the table was not found in the list of temporary tables + of this thread + @retval FALSE the table was found and dropped successfully. +*/ + bool close_temporary_table(THD *thd, const char *db, const char *table_name) { TABLE *table,**prev; @@ -1045,6 +1070,11 @@ bool close_temporary_table(THD *thd, const char *db, const char *table_name) return 1; table= *prev; *prev= table->next; + /* + If LOCK TABLES list is not empty and contains this table, + unlock the table and remove the table from this list. + */ + mysql_lock_remove(thd, thd->locked_tables, table, FALSE); close_temporary(table, 1); if (thd->slave_thread) --slave_open_temp_tables; @@ -1120,7 +1150,7 @@ TABLE *unlink_open_table(THD *thd, TABLE *list, TABLE *find) !memcmp(list->s->table_cache_key, key, key_length)) { if (thd->locked_tables) - mysql_lock_remove(thd, thd->locked_tables,list); + mysql_lock_remove(thd, thd->locked_tables, list, TRUE); VOID(hash_delete(&open_cache,(byte*) list)); // Close table } else @@ -1151,6 +1181,8 @@ TABLE *unlink_open_table(THD *thd, TABLE *list, TABLE *find) dropped is already unlocked. In the former case it will also remove lock on the table. But one should not rely on this behaviour as it may change in future. + Currently, however, this function is never called for a + table that was locked with LOCK TABLES. */ void drop_open_table(THD *thd, TABLE *table, const char *db_name, @@ -2099,7 +2131,7 @@ bool close_data_tables(THD *thd,const char *db, const char *table_name) if (!strcmp(table->s->table_name, table_name) && !strcmp(table->s->db, db)) { - mysql_lock_remove(thd, thd->locked_tables,table); + mysql_lock_remove(thd, thd->locked_tables, table, TRUE); table->file->close(); table->db_stat=0; } @@ -2239,7 +2271,7 @@ void close_old_data_files(THD *thd, TABLE *table, bool morph_locks, instances of this table. */ mysql_lock_abort(thd, table); - mysql_lock_remove(thd, thd->locked_tables, table); + mysql_lock_remove(thd, thd->locked_tables, table, TRUE); /* We want to protect the table from concurrent DDL operations (like RENAME TABLE) until we will re-open and re-lock it. @@ -2343,7 +2375,7 @@ bool drop_locked_tables(THD *thd,const char *db, const char *table_name) if (!strcmp(table->s->table_name, table_name) && !strcmp(table->s->db, db)) { - mysql_lock_remove(thd, thd->locked_tables,table); + mysql_lock_remove(thd, thd->locked_tables, table, TRUE); VOID(hash_delete(&open_cache,(byte*) table)); found=1; } |