summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNisha Gopalakrishnan <nisha.gopalakrishnan@oracle.com>2015-08-25 14:25:46 +0530
committerNisha Gopalakrishnan <nisha.gopalakrishnan@oracle.com>2015-08-25 14:25:46 +0530
commite414cbffad0e095c545cf2aa3f646c8a36c9b398 (patch)
treee33beec2ec8c00c95c6c0c405e4e9520bc235de4
parentf4ff086abea975222572fcfd232bf296018f5d85 (diff)
downloadmariadb-git-e414cbffad0e095c545cf2aa3f646c8a36c9b398.tar.gz
BUG#20449914: HANDLE_FATAL_SIGNAL (SIG=11) IN
FIELD_ITERATOR_TABLE::END_OF_FIELDS Note: This a backport of the patch for bug#19894987 to MySQL-5.5
-rw-r--r--sql/sql_base.cc14
-rw-r--r--sql/sql_handler.cc48
-rw-r--r--sql/sql_handler.h3
3 files changed, 60 insertions, 5 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 0b256974258..61a0d1ae909 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1648,13 +1648,20 @@ bool close_temporary_tables(THD *thd)
if (!thd->temporary_tables)
DBUG_RETURN(FALSE);
+ /*
+ Ensure we don't have open HANDLERs for tables we are about to close.
+ This is necessary when close_temporary_tables() is called as part
+ of execution of BINLOG statement (e.g. for format description event).
+ */
+ mysql_ha_rm_temporary_tables(thd);
if (!mysql_bin_log.is_open())
{
TABLE *tmp_next;
- for (table= thd->temporary_tables; table; table= tmp_next)
+ for (TABLE *t= thd->temporary_tables; t; t= tmp_next)
{
- tmp_next= table->next;
- close_temporary(table, 1, 1);
+ tmp_next= t->next;
+ mysql_lock_remove(thd, thd->lock, t);
+ close_temporary(t, 1, 1);
}
thd->temporary_tables= 0;
DBUG_RETURN(FALSE);
@@ -1744,6 +1751,7 @@ bool close_temporary_tables(THD *thd)
strlen(table->s->table_name.str));
s_query.append(',');
next= table->next;
+ mysql_lock_remove(thd, thd->lock, table);
close_temporary(table, 1, 1);
}
thd->clear_error();
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index b179d54eadf..2d8877db37a 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -1,4 +1,4 @@
-/* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1002,3 +1002,49 @@ void mysql_ha_set_explicit_lock_duration(THD *thd)
DBUG_VOID_RETURN;
}
+
+/**
+ Remove temporary tables from the HANDLER's hash table. The reason
+ for having a separate function, rather than calling
+ mysql_ha_rm_tables() is that it is not always feasible (e.g. in
+ close_temporary_tables) to obtain a TABLE_LIST containing the
+ temporary tables.
+
+ @See close_temporary_tables
+ @param thd Thread identifier.
+*/
+void mysql_ha_rm_temporary_tables(THD *thd)
+{
+ DBUG_ENTER("mysql_ha_rm_temporary_tables");
+
+ TABLE_LIST *tmp_handler_tables= NULL;
+ for (uint i= 0; i < thd->handler_tables_hash.records; i++)
+ {
+ TABLE_LIST *handler_table= reinterpret_cast<TABLE_LIST*>
+ (my_hash_element(&thd->handler_tables_hash, i));
+
+ if (handler_table->table && handler_table->table->s->tmp_table)
+ {
+ handler_table->next_local= tmp_handler_tables;
+ tmp_handler_tables= handler_table;
+ }
+ }
+
+ while (tmp_handler_tables)
+ {
+ TABLE_LIST *nl= tmp_handler_tables->next_local;
+ mysql_ha_close_table(thd, tmp_handler_tables);
+ my_hash_delete(&thd->handler_tables_hash, (uchar*) tmp_handler_tables);
+ tmp_handler_tables= nl;
+ }
+
+ /*
+ Mark MDL_context as no longer breaking protocol if we have
+ closed last HANDLER.
+ */
+ if (thd->handler_tables_hash.records == 0)
+ {
+ thd->mdl_context.set_needs_thr_lock_abort(FALSE);
+ }
+ DBUG_VOID_RETURN;
+}
diff --git a/sql/sql_handler.h b/sql/sql_handler.h
index b21d4595fce..c6d8c5ed0c0 100644
--- a/sql/sql_handler.h
+++ b/sql/sql_handler.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -32,5 +32,6 @@ void mysql_ha_flush_tables(THD *thd, TABLE_LIST *all_tables);
void mysql_ha_rm_tables(THD *thd, TABLE_LIST *tables);
void mysql_ha_cleanup(THD *thd);
void mysql_ha_set_explicit_lock_duration(THD *thd);
+void mysql_ha_rm_temporary_tables(THD *thd);
#endif /* SQL_HANDLER_INCLUDED */