| 10157 | */ |
| 10158 | |
| 10159 | bool TABLE_LIST::init_derived(THD *thd, bool init_view) |
| 10160 | { |
| 10161 | SELECT_LEX *first_select= get_single_select(); |
| 10162 | SELECT_LEX_UNIT *unit= get_unit(); |
| 10163 | |
| 10164 | if (!unit) |
| 10165 | return FALSE; |
| 10166 | /* |
| 10167 | Check whether we can merge this derived table into main select. |
| 10168 | Depending on the result field translation will or will not |
| 10169 | be created. |
| 10170 | */ |
| 10171 | TABLE_LIST *first_table= (TABLE_LIST *) first_select->table_list.first; |
| 10172 | if (first_select->table_list.elements > 1 || |
| 10173 | (first_table && first_table->is_multitable())) |
| 10174 | set_multitable(); |
| 10175 | |
| 10176 | if (!unit->derived) |
| 10177 | unit->derived= this; |
| 10178 | else if (!is_with_table_recursive_reference() && unit->derived != this) |
| 10179 | { |
| 10180 | if (unit->derived->is_with_table_recursive_reference()) |
| 10181 | unit->derived= this; |
| 10182 | else if (vers_conditions.eq(unit->derived->vers_conditions)) |
| 10183 | vers_conditions.empty(); |
| 10184 | else |
| 10185 | { |
| 10186 | my_error(ER_CONFLICTING_FOR_SYSTEM_TIME, MYF(0)); |
| 10187 | return TRUE; |
| 10188 | } |
| 10189 | } |
| 10190 | |
| 10191 | if (init_view && !view && |
| 10192 | !derived_table_optimization_done(this)) |
| 10193 | { |
| 10194 | /* This is all what we can do for a derived table for now. */ |
| 10195 | set_derived(); |
| 10196 | } |
| 10197 | |
| 10198 | if (!derived_table_optimization_done(this)) |
| 10199 | { |
| 10200 | /* A subquery might be forced to be materialized due to a side-effect. */ |
| 10201 | bool forced_no_merge_for_update_delete= |
| 10202 | belong_to_view ? belong_to_view->updating : |
| 10203 | !unit->outer_select()->outer_select(); |
| 10204 | |
| 10205 | if (with && updating) |
| 10206 | { |
| 10207 | /* |
| 10208 | We are trying to update or delete from a CTE. This is not allowed. |
| 10209 | Don't merge it, then the check for update of non-updatable table |
| 10210 | will catch this and report an error. |
| 10211 | */ |
| 10212 | set_materialized_derived(); |
| 10213 | } |
| 10214 | |
| 10215 | /* |
| 10216 | In the case where a table merge operation moves a derived table from |
no test coverage detected