summaryrefslogtreecommitdiff
path: root/sql/sql_update.cc
diff options
context:
space:
mode:
authorJon Olav Hauglid <jon.hauglid@oracle.com>2010-12-16 10:55:23 +0100
committerJon Olav Hauglid <jon.hauglid@oracle.com>2010-12-16 10:55:23 +0100
commit28a5059a92707e009aada358bf103fa386ea7c2c (patch)
treebd7b8cee8615e737092897bcfb4e3d0d2eac5cd1 /sql/sql_update.cc
parentcaebacaf93a758f5a35f85cb814a5b76402a1f3d (diff)
downloadmariadb-git-28a5059a92707e009aada358bf103fa386ea7c2c.tar.gz
Bug #58730 Assertion failed: table->key_read == 0 in close_thread_table,
temptable views The TABLE::key_read field indicates if the optimizer has found that row retrieval only should access the index tree. The triggered assert inside close_thread_table() checks that this field has been reset when the table is about to be closed. During normal execution, these fields are reset right before tables are closed at the end of mysql_execute_command(). But in the case of errors, tables are closed earlier. The patch for Bug#52044 refactored the open tables code so that close_thread_tables() is called immediately if opening of tables fails. At this point in the execution, it could happend that all TABLE::key_read fields had not been properly reset, therefore triggering the assert. The problematic statement in this case was EXPLAIN where the query accessed two derived tables and where the first derived table was processed successfully while the second derived table was not. Since it was an EXPLAIN, TABLE::key_read fields were not reset after successful derived table processing since the state needs to be accessible afterwards. When processing of the second derived table failed, it's corresponding SELECT_LEX_UNIT was cleaned, which caused it's TABLE::key_read fields to be reset. Since processing failed, the error path of open_and_lock_tables() was entered and close_thread_tables() was called. The assert was then triggered due to the TABLE::key_read fields set during processing of the first derived table. This patch fixes the problem by adding a new derived table processor, mysql_derived_cleanup() that is called after mysql_derived_filling(). It causes cleanup of all SELECT_LEX_UNITs to be called, resetting all relevant TABLE::key_read fields. Test case added to derived.test.
Diffstat (limited to 'sql/sql_update.cc')
-rw-r--r--sql/sql_update.cc16
1 files changed, 13 insertions, 3 deletions
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index b49ed2beafe..082c603bb5a 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -296,11 +296,17 @@ int mysql_update(THD *thd,
if (lock_tables(thd, table_list, table_count, 0))
DBUG_RETURN(1);
- if (mysql_handle_derived(thd->lex, &mysql_derived_prepare) ||
- (thd->fill_derived_tables() &&
- mysql_handle_derived(thd->lex, &mysql_derived_filling)))
+ if (mysql_handle_derived(thd->lex, &mysql_derived_prepare))
DBUG_RETURN(1);
+ if (thd->fill_derived_tables() &&
+ mysql_handle_derived(thd->lex, &mysql_derived_filling))
+ {
+ mysql_handle_derived(thd->lex, &mysql_derived_cleanup);
+ DBUG_RETURN(1);
+ }
+ mysql_handle_derived(thd->lex, &mysql_derived_cleanup);
+
thd_proc_info(thd, "init");
table= table_list->table;
@@ -1194,7 +1200,11 @@ int mysql_multi_update_prepare(THD *thd)
if (thd->fill_derived_tables() &&
mysql_handle_derived(lex, &mysql_derived_filling))
+ {
+ mysql_handle_derived(lex, &mysql_derived_cleanup);
DBUG_RETURN(TRUE);
+ }
+ mysql_handle_derived(lex, &mysql_derived_cleanup);
DBUG_RETURN (FALSE);
}