| 77 | |
| 78 | |
| 79 | void Item_subselect::init(st_select_lex *select_lex, |
| 80 | select_result_interceptor *result) |
| 81 | { |
| 82 | /* |
| 83 | Please see Item_singlerow_subselect::invalidate_and_restore_select_lex(), |
| 84 | which depends on alterations to the parse tree implemented here. |
| 85 | */ |
| 86 | |
| 87 | DBUG_ENTER("Item_subselect::init"); |
| 88 | DBUG_PRINT("enter", ("select_lex: %p this: %p", |
| 89 | select_lex, this)); |
| 90 | |
| 91 | select_lex->parent_lex->relink_hack(select_lex); |
| 92 | |
| 93 | unit= select_lex->master_unit(); |
| 94 | |
| 95 | if (unit->item) |
| 96 | { |
| 97 | engine= unit->item->engine; |
| 98 | parsing_place= unit->item->parsing_place; |
| 99 | if (unit->item->substype() == EXISTS_SUBS && |
| 100 | ((Item_exists_subselect *)unit->item)->exists_transformed) |
| 101 | { |
| 102 | /* it is permanent transformation of EXISTS to IN */ |
| 103 | unit->item= this; |
| 104 | engine->change_result(this, result, FALSE); |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | /* |
| 109 | Item can be changed in JOIN::prepare while engine in JOIN::optimize |
| 110 | => we do not copy old_engine here |
| 111 | */ |
| 112 | unit->thd->change_item_tree((Item**)&unit->item, this); |
| 113 | engine->change_result(this, result, TRUE); |
| 114 | } |
| 115 | } |
| 116 | else |
| 117 | { |
| 118 | SELECT_LEX *outer_select= unit->outer_select(); |
| 119 | THD *thd= unit->thd; |
| 120 | /* |
| 121 | do not take into account expression inside aggregate functions because |
| 122 | they can access original table fields |
| 123 | */ |
| 124 | parsing_place= (outer_select->in_sum_expr ? |
| 125 | NO_MATTER : |
| 126 | outer_select->parsing_place); |
| 127 | if (unit->is_unit_op() && |
| 128 | (unit->first_select()->next_select() || unit->fake_select_lex)) |
| 129 | engine= new (thd->mem_root) |
| 130 | subselect_union_engine(unit, result, this); |
| 131 | else |
| 132 | engine= new (thd->mem_root) |
| 133 | subselect_single_select_engine(select_lex, result, this); |
| 134 | } |
| 135 | DBUG_PRINT("info", ("engine: %p", engine)); |
| 136 | DBUG_VOID_RETURN; |
no test coverage detected