| 5094 | |
| 5095 | |
| 5096 | static bool |
| 5097 | add_internal_tables(THD *thd, Query_tables_list *prelocking_ctx, |
| 5098 | TABLE_LIST *tables) |
| 5099 | { |
| 5100 | TABLE_LIST *global_table_list= prelocking_ctx->query_tables; |
| 5101 | DBUG_ENTER("add_internal_tables"); |
| 5102 | |
| 5103 | do |
| 5104 | { |
| 5105 | TABLE_LIST *tmp __attribute__((unused)); |
| 5106 | DBUG_PRINT("info", ("table name: %s", tables->table_name.str)); |
| 5107 | /* |
| 5108 | Skip table if already in the list. Can happen with prepared statements |
| 5109 | */ |
| 5110 | if ((tmp= internal_table_exists(global_table_list, tables))) |
| 5111 | { |
| 5112 | /* |
| 5113 | Use the original value for the next local, used by the |
| 5114 | original prepared statement. We cannot trust the original |
| 5115 | next_local value as it may have been changed by a previous |
| 5116 | statement using the same table. |
| 5117 | */ |
| 5118 | tmp->linked_table= tables; |
| 5119 | continue; |
| 5120 | } |
| 5121 | |
| 5122 | /* |
| 5123 | Debug hook: Verify we only allocate once per internal table. |
| 5124 | */ |
| 5125 | DBUG_EXECUTE_IF("assert_no_alloc_internal_tables", { DBUG_ASSERT(0); }); |
| 5126 | |
| 5127 | /* |
| 5128 | When a prepared statement uses DEFAULT (like sequence tables) in its |
| 5129 | second or further execution AND if the table is not already on statement's |
| 5130 | mem_root, temporarily allow allocating on statement mem_root. |
| 5131 | */ |
| 5132 | #ifdef PROTECT_STATEMENT_MEMROOT |
| 5133 | const bool read_only_mem_root= (thd->mem_root->flags & ROOT_FLAG_READ_ONLY); |
| 5134 | if (read_only_mem_root) |
| 5135 | thd->mem_root->flags&= ~ROOT_FLAG_READ_ONLY; |
| 5136 | #endif |
| 5137 | |
| 5138 | TABLE_LIST *tl= thd->alloc<TABLE_LIST>(1); |
| 5139 | |
| 5140 | #ifdef PROTECT_STATEMENT_MEMROOT |
| 5141 | if (read_only_mem_root) |
| 5142 | thd->mem_root->flags|= ROOT_FLAG_READ_ONLY; |
| 5143 | #endif |
| 5144 | |
| 5145 | if (!tl) |
| 5146 | DBUG_RETURN(TRUE); |
| 5147 | tl->init_one_table_for_prelocking(&tables->db, |
| 5148 | &tables->table_name, |
| 5149 | NULL, tables->lock_type, |
| 5150 | TABLE_LIST::PRELOCK_NONE, |
| 5151 | 0, 0, |
| 5152 | &prelocking_ctx->query_tables_last, |
| 5153 | tables->for_insert_data); |
no test coverage detected