| 2962 | */ |
| 2963 | |
| 2964 | bool |
| 2965 | Locked_tables_list::reopen_tables(THD *thd, bool need_reopen) |
| 2966 | { |
| 2967 | bool is_ok= thd->get_stmt_da()->is_ok(); |
| 2968 | Open_table_context ot_ctx(thd, !is_ok ? MYSQL_OPEN_REOPEN: |
| 2969 | MYSQL_OPEN_IGNORE_KILLED | MYSQL_OPEN_REOPEN); |
| 2970 | uint reopen_count= 0; |
| 2971 | MYSQL_LOCK *lock; |
| 2972 | MYSQL_LOCK *merged_lock; |
| 2973 | DBUG_ENTER("Locked_tables_list::reopen_tables"); |
| 2974 | |
| 2975 | DBUG_ASSERT(some_table_marked_for_reopen || !need_reopen); |
| 2976 | |
| 2977 | |
| 2978 | /* Reset flag that some table was marked for reopen */ |
| 2979 | if (need_reopen) |
| 2980 | some_table_marked_for_reopen= 0; |
| 2981 | |
| 2982 | for (TABLE_LIST *table_list= m_locked_tables; |
| 2983 | table_list; table_list= table_list->next_global) |
| 2984 | { |
| 2985 | if (need_reopen) |
| 2986 | { |
| 2987 | if (!table_list->table || !table_list->table->needs_reopen()) |
| 2988 | continue; |
| 2989 | for (TABLE **prev= &thd->open_tables; *prev; prev= &(*prev)->next) |
| 2990 | { |
| 2991 | if (*prev == table_list->table) |
| 2992 | { |
| 2993 | thd->locked_tables_list.unlink_from_list(thd, table_list, false); |
| 2994 | mysql_lock_remove(thd, thd->lock, *prev); |
| 2995 | (*prev)->file->extra(HA_EXTRA_PREPARE_FOR_FORCED_CLOSE); |
| 2996 | close_thread_table(thd, prev); |
| 2997 | break; |
| 2998 | } |
| 2999 | } |
| 3000 | DBUG_ASSERT(table_list->table == NULL); |
| 3001 | } |
| 3002 | else |
| 3003 | { |
| 3004 | if (table_list->table) /* The table was not closed */ |
| 3005 | continue; |
| 3006 | } |
| 3007 | |
| 3008 | DBUG_ASSERT(reopen_count < m_locked_tables_count); |
| 3009 | m_reopen_array[reopen_count++]= table_list; |
| 3010 | } |
| 3011 | if (reopen_count) |
| 3012 | { |
| 3013 | TABLE **tables= (TABLE**) my_alloca(reopen_count * sizeof(TABLE*)); |
| 3014 | |
| 3015 | for (uint i= 0 ; i < reopen_count ; i++) |
| 3016 | { |
| 3017 | TABLE_LIST *table_list= m_reopen_array[i]; |
| 3018 | /* Links into thd->open_tables upon success */ |
| 3019 | if (open_table(thd, table_list, &ot_ctx)) |
| 3020 | { |
| 3021 | unlink_all_closed_tables(thd, 0, i); |
no test coverage detected