summaryrefslogtreecommitdiff
path: root/sql/table.h
diff options
context:
space:
mode:
authordavi@endora.local <>2007-11-01 18:52:56 -0200
committerdavi@endora.local <>2007-11-01 18:52:56 -0200
commitcc007acb785d12cb6f5f176320ad9d099937fd9c (patch)
tree6665bd29057800c65aa07195e3d351558f7d3173 /sql/table.h
parent6bd9f5c1cb1875b1a0b962a29c408f299222479e (diff)
downloadmariadb-git-cc007acb785d12cb6f5f176320ad9d099937fd9c.tar.gz
Bug#30882 Dropping a temporary table inside a stored function may cause a server crash
If a stored function that contains a drop temporary table statement is invoked by a create temporary table of the same name may cause a server crash. The problem is that when dropping a table no check is done to ensure that table is not being used by some outer query (or outer statement), potentially leaving the outer query with a reference to a stale (freed) table. The solution is when dropping a temporary table, always check if the table is being used by some outer statement as a temporary table can be dropped inside stored procedures. The check is performed by looking at the TABLE::query_id value for temporary tables. To simplify this check and to solve a bug related to handling of temporary tables in prelocked mode, this patch changes the way in which this member is used to track the fact that table is used/unused. Now we ensure that TABLE::query_id is zero for unused temporary tables (which means that all temporary tables which were used by a statement should be marked as free for reuse after it's execution has been completed).
Diffstat (limited to 'sql/table.h')
-rw-r--r--sql/table.h22
1 files changed, 20 insertions, 2 deletions
diff --git a/sql/table.h b/sql/table.h
index 6554b6ed578..2bbd71b70c6 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -499,6 +499,24 @@ struct st_table {
my_bitmap_map *bitmap_init_value;
MY_BITMAP def_read_set, def_write_set, tmp_set; /* containers */
MY_BITMAP *read_set, *write_set; /* Active column sets */
+ /*
+ The ID of the query that opened and is using this table. Has different
+ meanings depending on the table type.
+
+ Temporary tables:
+
+ table->query_id is set to thd->query_id for the duration of a statement
+ and is reset to 0 once it is closed by the same statement. A non-zero
+ table->query_id means that a statement is using the table even if it's
+ not the current statement (table is in use by some outer statement).
+
+ Non-temporary tables:
+
+ Under pre-locked or LOCK TABLES mode: query_id is set to thd->query_id
+ for the duration of a statement and is reset to 0 once it is closed by
+ the same statement. A non-zero query_id is used to control which tables
+ in the list of pre-opened and locked tables are actually being used.
+ */
query_id_t query_id;
/*
@@ -593,8 +611,8 @@ struct st_table {
my_bool locked_by_name;
my_bool fulltext_searched;
my_bool no_cache;
- /* To signal that we should reset query_id for tables and cols */
- my_bool clear_query_id;
+ /* To signal that the table is associated with a HANDLER statement */
+ my_bool open_by_handler;
/*
To indicate that a non-null value of the auto_increment field
was provided by the user or retrieved from the current record.