36
mysql_handle_derived(LEX *lex, bool (*processor)(THD*, LEX*, TABLE_LIST*))
36
mysql_handle_derived(LEX *lex, bool (*processor)(Session*, LEX*, TableList*))
39
39
if (lex->derived_tables)
41
lex->thd->derived_tables_processing= true;
41
lex->session->derived_tables_processing= true;
42
42
for (SELECT_LEX *sl= lex->all_selects_list;
44
44
sl= sl->next_select_in_list())
46
for (TABLE_LIST *cursor= sl->get_table_list();
46
for (TableList *cursor= sl->get_table_list();
48
48
cursor= cursor->next_local)
50
if ((res= (*processor)(lex->thd, lex, cursor)))
50
if ((res= (*processor)(lex->session, lex, cursor)))
74
74
mysql_derived_prepare()
76
76
lex LEX for this thread
77
orig_table_list TABLE_LIST for the upper SELECT
77
orig_table_list TableList for the upper SELECT
80
80
Derived table is resolved with temporary table.
82
After table creation, the above TABLE_LIST is updated with a new table.
82
After table creation, the above TableList is updated with a new table.
84
84
This function is called before any command containing derived table
87
Derived tables is stored in thd->derived_tables and freed in
87
Derived tables is stored in session->derived_tables and freed in
88
88
close_thread_tables()
95
bool mysql_derived_prepare(THD *thd, LEX *lex __attribute__((unused)),
96
TABLE_LIST *orig_table_list)
95
bool mysql_derived_prepare(Session *session, LEX *,
96
TableList *orig_table_list)
98
98
SELECT_LEX_UNIT *unit= orig_table_list->derived;
99
99
uint64_t create_options;
112
112
return(true); // out of memory
114
114
// st_select_lex_unit::prepare correctly work for single select
115
if ((res= unit->prepare(thd, derived_result, 0)))
115
if ((res= unit->prepare(session, derived_result, 0)))
118
create_options= (first_select->options | thd->options |
118
create_options= (first_select->options | session->options |
119
119
TMP_TABLE_ALL_COLUMNS);
121
Temp table is created so that it hounours if UNION without ALL is to be
121
Temp table is created so that it hounours if UNION without ALL is to be
124
124
As 'distinct' parameter we always pass false (0), because underlying
127
127
!unit->union_distinct->next_select() (i.e. it is union and last distinct
128
128
SELECT is last SELECT of UNION).
130
if ((res= derived_result->create_result_table(thd, &unit->types, false,
130
if ((res= derived_result->create_result_table(session, &unit->types, false,
132
132
orig_table_list->alias,
147
free_tmp_table(thd, table);
147
table->free_tmp_table(session);
148
148
delete derived_result;
152
if (!thd->fill_derived_tables())
152
if (!session->fill_derived_tables())
154
154
delete derived_result;
155
155
derived_result= NULL;
165
165
// Force read of table stats in the optimizer
166
166
table->file->info(HA_STATUS_VARIABLE);
167
167
/* Add new temporary table to list of open derived tables */
168
table->next= thd->derived_tables;
169
thd->derived_tables= table;
168
table->next= session->derived_tables;
169
session->derived_tables= table;
181
181
mysql_derived_filling()
182
session Thread handle
183
183
lex LEX for this thread
184
184
unit node that contains all SELECT's for derived tables
185
orig_table_list TABLE_LIST for the upper SELECT
185
orig_table_list TableList for the upper SELECT
188
188
Derived table is resolved with temporary table. It is created based on the
200
bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *orig_table_list)
200
bool mysql_derived_filling(Session *session, LEX *lex, TableList *orig_table_list)
202
TABLE *table= orig_table_list->table;
202
Table *table= orig_table_list->table;
203
203
SELECT_LEX_UNIT *unit= orig_table_list->derived;
221
221
first_select->options&= ~OPTION_FOUND_ROWS;
223
223
lex->current_select= first_select;
224
res= mysql_select(thd, &first_select->ref_pointer_array,
225
(TABLE_LIST*) first_select->table_list.first,
224
res= mysql_select(session, &first_select->ref_pointer_array,
225
(TableList*) first_select->table_list.first,
226
226
first_select->with_wild,
227
227
first_select->item_list, first_select->where,
228
228
(first_select->order_list.elements+
229
229
first_select->group_list.elements),
230
(ORDER *) first_select->order_list.first,
231
(ORDER *) first_select->group_list.first,
232
first_select->having, (ORDER*) NULL,
233
(first_select->options | thd->options |
230
(order_st *) first_select->order_list.first,
231
(order_st *) first_select->group_list.first,
232
first_select->having, (order_st*) NULL,
233
(first_select->options | session->options |
234
234
SELECT_NO_UNLOCK),
235
235
derived_result, unit, first_select);