summaryrefslogtreecommitdiff
path: root/sql/sql_table.cc
diff options
context:
space:
mode:
authorNisha Gopalakrishnan <nisha.gopalakrishnan@oracle.com>2018-02-26 14:37:39 +0530
committerNisha Gopalakrishnan <nisha.gopalakrishnan@oracle.com>2018-02-26 14:37:39 +0530
commitc0b4d74b52e7eec9b13af732193f7f8d7abe05de (patch)
treef9a56f685812262c4a9e3a7c8972207addefd277 /sql/sql_table.cc
parent873f8c25b6de24d267cbdedc70de40dc4b5b83aa (diff)
downloadmariadb-git-c0b4d74b52e7eec9b13af732193f7f8d7abe05de.tar.gz
BUG#27216817: INNODB: FAILING ASSERTION:mysql-5.5.60
PREBUILT->TABLE->N_MYSQL_HANDLES_OPENED == 1 ANALYSIS: ========= Adding unique index to a InnoDB table which is locked as mutliple instances may trigger an InnoDB assert. When we add a primary key or an unique index, we need to drop the original table and rebuild all indexes. InnoDB expects that only the instance of the table that is being rebuilt, is open during the process. In the current scenario we have opened multiple instances of the table. This triggers an assert during table rebuild. 'Locked_tables_list' encapsulates a list of all instances of tables locked by LOCK TABLES statement. FIX: === We are now temporarily closing all the instances of the table except the one which is being altered and later reopen them via Locked_tables_list::reopen_tables().
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r--sql/sql_table.cc22
1 files changed, 18 insertions, 4 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 58bcf5ca1d4..6d02140cfcb 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2000, 2018, 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
@@ -2165,7 +2165,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
error= -1;
goto err;
}
- close_all_tables_for_name(thd, table->table->s, TRUE);
+ close_all_tables_for_name(thd, table->table->s, TRUE, NULL);
table->table= 0;
}
@@ -6168,7 +6168,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
*/
if (wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN))
goto err;
- close_all_tables_for_name(thd, table->s, TRUE);
+ close_all_tables_for_name(thd, table->s, TRUE, NULL);
/*
Then, we want check once again that target table does not exist.
Actually the order of these two steps does not matter since
@@ -6305,6 +6305,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
changes only" means also that the handler for the table does not
change. The table is open and locked. The handler can be accessed.
*/
+
if (need_copy_table == ALTER_TABLE_INDEX_CHANGED)
{
int pk_changed= 0;
@@ -6606,6 +6607,19 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
thd->count_cuted_fields= CHECK_FIELD_WARN; // calc cuted fields
thd->cuted_fields=0L;
copied=deleted=0;
+
+ if (thd->locked_tables_mode == LTM_LOCK_TABLES ||
+ thd->locked_tables_mode == LTM_PRELOCKED_UNDER_LOCK_TABLES)
+ {
+ /*
+ Temporarily close the TABLE instances belonging to this
+ thread except the one to be used for ALTER TABLE.
+
+ This is mostly needed to satisfy InnoDB assumptions/asserts.
+ */
+ close_all_tables_for_name(thd, table->s, false, table);
+ }
+
/*
We do not copy data for MERGE tables. Only the children have data.
MERGE tables have HA_NO_COPY_ON_ALTER set.
@@ -6877,7 +6891,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
}
close_all_tables_for_name(thd, table->s,
- new_name != table_name || new_db != db);
+ new_name != table_name || new_db != db, NULL);
error=0;
table_list->table= table= 0; /* Safety */