| 2169 | */ |
| 2170 | |
| 2171 | bool |
| 2172 | multi_update::initialize_tables(JOIN *join) |
| 2173 | { |
| 2174 | TABLE_LIST *table_ref; |
| 2175 | DBUG_ENTER("initialize_tables"); |
| 2176 | |
| 2177 | if (unlikely((thd->variables.option_bits & OPTION_SAFE_UPDATES) && |
| 2178 | error_if_full_join(join))) |
| 2179 | DBUG_RETURN(1); |
| 2180 | if (join->implicit_grouping || |
| 2181 | join->select_lex->have_window_funcs()) |
| 2182 | { |
| 2183 | my_error(ER_INVALID_GROUP_FUNC_USE, MYF(0)); |
| 2184 | DBUG_RETURN(1); |
| 2185 | } |
| 2186 | main_table=join->join_tab->table; |
| 2187 | table_to_update= 0; |
| 2188 | |
| 2189 | /* Any update has at least one pair (field, value) */ |
| 2190 | DBUG_ASSERT(fields->elements); |
| 2191 | /* |
| 2192 | Only one table may be modified by UPDATE of an updatable view. |
| 2193 | For an updatable view first_table_for_update indicates this |
| 2194 | table. |
| 2195 | For a regular multi-update it refers to some updated table. |
| 2196 | */ |
| 2197 | TABLE *first_table_for_update= ((Item_field *) fields->head())->field->table; |
| 2198 | |
| 2199 | /* Create a temporary table for keys to all tables, except main table */ |
| 2200 | for (table_ref= update_tables; table_ref; table_ref= table_ref->next_local) |
| 2201 | { |
| 2202 | TABLE *table=table_ref->table; |
| 2203 | uint index= table_ref->shared; |
| 2204 | List<Item> temp_fields; |
| 2205 | ORDER group; |
| 2206 | TMP_TABLE_PARAM *tmp_param; |
| 2207 | |
| 2208 | table->file->prepare_for_modify(true, true); |
| 2209 | |
| 2210 | if (ignore) |
| 2211 | table->file->extra(HA_EXTRA_IGNORE_DUP_KEY); |
| 2212 | if (table == main_table) // First table in join |
| 2213 | { |
| 2214 | if (safe_update_on_fly(thd, join->join_tab, table_ref, all_tables)) |
| 2215 | { |
| 2216 | table_to_update= table; // Update table on the fly |
| 2217 | has_vers_fields= table->vers_check_update(*fields); |
| 2218 | continue; |
| 2219 | } |
| 2220 | } |
| 2221 | table->prepare_for_position(); |
| 2222 | join->map2table[table->tablenr]->keep_current_rowid= true; |
| 2223 | |
| 2224 | /* |
| 2225 | enable uncacheable flag if we update a view with check option |
| 2226 | and check option has a subselect, otherwise, the check option |
| 2227 | can be evaluated after the subselect was freed as independent |
| 2228 | (See full_local in JOIN::join_free()). |
nothing calls this directly
no test coverage detected