|  | 
| 1 | 1 | /* | 
| 2 |  | -   Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. | 
|  | 2 | +   Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. | 
| 3 | 3 | 
 | 
| 4 | 4 |    This program is free software; you can redistribute it and/or modify | 
| 5 | 5 |    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, | 
| 2165 | 2165 |           error= -1; | 
| 2166 | 2166 |           goto err; | 
| 2167 | 2167 |         } | 
| 2168 |  | -        close_all_tables_for_name(thd, table->table->s, TRUE); | 
|  | 2168 | +        close_all_tables_for_name(thd, table->table->s, TRUE, NULL); | 
| 2169 | 2169 |         table->table= 0; | 
| 2170 | 2170 |       } | 
| 2171 | 2171 | 
 | 
| @@ -6168,7 +6168,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, | 
| 6168 | 6168 |       */ | 
| 6169 | 6169 |       if (wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN)) | 
| 6170 | 6170 |         goto err; | 
| 6171 |  | -      close_all_tables_for_name(thd, table->s, TRUE); | 
|  | 6171 | +      close_all_tables_for_name(thd, table->s, TRUE, NULL); | 
| 6172 | 6172 |       /* | 
| 6173 | 6173 |         Then, we want check once again that target table does not exist. | 
| 6174 | 6174 |         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, | 
| 6305 | 6305 |     changes only" means also that the handler for the table does not | 
| 6306 | 6306 |     change. The table is open and locked. The handler can be accessed. | 
| 6307 | 6307 |   */ | 
|  | 6308 | + | 
| 6308 | 6309 |   if (need_copy_table == ALTER_TABLE_INDEX_CHANGED) | 
| 6309 | 6310 |   { | 
| 6310 | 6311 |     int   pk_changed= 0; | 
| @@ -6606,6 +6607,19 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, | 
| 6606 | 6607 |   thd->count_cuted_fields= CHECK_FIELD_WARN;	// calc cuted fields | 
| 6607 | 6608 |   thd->cuted_fields=0L; | 
| 6608 | 6609 |   copied=deleted=0; | 
|  | 6610 | + | 
|  | 6611 | +  if (thd->locked_tables_mode == LTM_LOCK_TABLES || | 
|  | 6612 | +      thd->locked_tables_mode == LTM_PRELOCKED_UNDER_LOCK_TABLES) | 
|  | 6613 | +  { | 
|  | 6614 | +    /* | 
|  | 6615 | +      Temporarily close the TABLE instances belonging to this | 
|  | 6616 | +      thread except the one to be used for ALTER TABLE. | 
|  | 6617 | +
 | 
|  | 6618 | +      This is mostly needed to satisfy InnoDB assumptions/asserts. | 
|  | 6619 | +    */ | 
|  | 6620 | +     close_all_tables_for_name(thd, table->s, false, table); | 
|  | 6621 | +  } | 
|  | 6622 | + | 
| 6609 | 6623 |   /* | 
| 6610 | 6624 |     We do not copy data for MERGE tables. Only the children have data. | 
| 6611 | 6625 |     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, | 
| 6877 | 6891 |   } | 
| 6878 | 6892 | 
 | 
| 6879 | 6893 |   close_all_tables_for_name(thd, table->s, | 
| 6880 |  | -                            new_name != table_name || new_db != db); | 
|  | 6894 | +                            new_name != table_name || new_db != db, NULL); | 
| 6881 | 6895 | 
 | 
| 6882 | 6896 |   error=0; | 
| 6883 | 6897 |   table_list->table= table= 0;                  /* Safety */ | 
|  | 
0 commit comments