22 #include <drizzled/sql_lex.h>
23 #include <drizzled/select_union.h>
24 #include <drizzled/sql_select.h>
25 #include <drizzled/session.h>
26 #include <drizzled/open_tables_state.h>
42 bool handle_derived(LEX *lex,
bool (*processor)(Session*, LEX*, TableList*))
45 if (lex->derived_tables)
47 lex->session->derived_tables_processing=
true;
48 for (Select_Lex *sl= lex->all_selects_list; sl; sl= sl->next_select_in_list())
50 for (TableList *cursor= sl->get_table_list(); cursor; cursor= cursor->next_local)
52 if ((res= (*processor)(lex->session, lex, cursor)))
67 lex->session->derived_tables_processing=
false;
95 bool derived_prepare(Session *session, LEX *, TableList *orig_table_list)
97 Select_Lex_Unit *unit= orig_table_list->derived;
98 uint64_t create_options;
102 Select_Lex *first_select= unit->first_select();
104 select_union *derived_result;
107 for (Select_Lex *sl= first_select; sl; sl= sl->next_select())
108 sl->context.outer_context= 0;
110 derived_result=
new select_union;
113 if ((res= unit->prepare(session, derived_result, 0)))
116 create_options= (first_select->options | session->options | TMP_TABLE_ALL_COLUMNS);
127 if ((res= derived_result->create_result_table(session, &unit->types,
false,
129 orig_table_list->alias)))
132 table= derived_result->table;
143 delete derived_result;
147 orig_table_list->derived_result= derived_result;
148 orig_table_list->table= table;
149 orig_table_list->setTableName(table->getShare()->getTableName());
150 table->derived_select_number= first_select->select_number;
151 orig_table_list->setSchemaName(
"");
153 table->cursor->info(HA_STATUS_VARIABLE);
155 table->setNext(session->open_tables.getDerivedTables());
156 session->open_tables.setDerivedTables(table);
185 bool derived_filling(Session *session, LEX *lex, TableList *orig_table_list)
187 Table *table= orig_table_list->table;
188 Select_Lex_Unit *unit= orig_table_list->derived;
194 Select_Lex *first_select= unit->first_select();
195 select_union *derived_result= orig_table_list->derived_result;
196 Select_Lex *save_current_select= lex->current_select;
197 if (unit->is_union())
204 unit->set_limit(first_select);
205 if (unit->select_limit_cnt == HA_POS_ERROR)
206 first_select->options&= ~OPTION_FOUND_ROWS;
208 lex->current_select= first_select;
209 res=
select_query(session, &first_select->ref_pointer_array,
210 (TableList*) first_select->table_list.first,
211 first_select->with_wild,
212 first_select->item_list, first_select->where,
213 (first_select->order_list.elements+
214 first_select->group_list.elements),
215 (Order *) first_select->order_list.first,
216 (Order *) first_select->group_list.first,
217 first_select->having,
218 (first_select->options | session->options | SELECT_NO_UNLOCK),
219 derived_result, unit, first_select);
228 if (derived_result->flush())
236 lex->current_select= save_current_select;
bool select_query(Session *session, Item ***rref_pointer_array, TableList *tables, uint32_t wild_num, List< Item > &fields, COND *conds, uint32_t og_num, Order *order, Order *group, Item *having, uint64_t select_options, select_result *result, Select_Lex_Unit *unit, Select_Lex *select_lex)
static const uint32_t UNCACHEABLE_EXPLAIN
forcing to save JOIN for explain