13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
19
UNION's were introduced by Monty and Sinisa <sinisa@mysql.com>
20
#include <drizzled/server_includes.h>
21
#include <drizzled/sql_select.h>
22
#include <drizzled/drizzled_error_messages.h>
23
#include "mysql_priv.h"
24
#include "sql_select.h"
24
26
bool mysql_union(THD *thd,
25
LEX *lex __attribute__((unused)),
27
LEX *lex __attribute__((__unused__)),
26
28
select_result *result,
27
29
SELECT_LEX_UNIT *unit, ulong setup_tables_done_option)
40
42
** store records in temporary table for UNION
41
43
***************************************************************************/
43
int select_union::prepare(List<Item> &list __attribute__((unused)),
45
int select_union::prepare(List<Item> &list __attribute__((__unused__)),
44
46
SELECT_LEX_UNIT *u)
124
126
tmp_table_param.bit_fields_as_long= bit_fields_as_long;
126
128
if (! (table= create_tmp_table(thd_arg, &tmp_table_param, *column_types,
127
(order_st*) 0, is_union_distinct, 1,
129
(ORDER*) 0, is_union_distinct, 1,
128
130
options, HA_POS_ERROR, (char*) table_alias)))
130
132
table->file->extra(HA_EXTRA_WRITE_CACHE);
164
166
st_select_lex_unit::init_prepare_fake_select_lex(THD *thd_arg)
166
168
thd_arg->lex->current_select= fake_select_lex;
167
fake_select_lex->table_list.link_in_list((unsigned char *)&result_table_list,
169
fake_select_lex->table_list.link_in_list((uchar *)&result_table_list,
169
171
&result_table_list.next_local);
170
172
fake_select_lex->context.table_list=
171
173
fake_select_lex->context.first_name_resolution_table=
172
174
fake_select_lex->get_table_list();
174
for (order_st *order= (order_st *) global_parameters->order_list.first;
177
order->item= &order->item_ptr;
179
for (order_st *order= (order_st *)global_parameters->order_list.first;
175
if (!fake_select_lex->first_execution)
177
for (ORDER *order= (ORDER *) global_parameters->order_list.first;
180
order->item= &order->item_ptr;
182
for (ORDER *order= (ORDER *)global_parameters->order_list.first;
181
184
order=order->next)
183
186
(*order->item)->walk(&Item::change_context_processor, 0,
184
(unsigned char*) &fake_select_lex->context);
187
(uchar*) &fake_select_lex->context);
189
192
bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
190
uint32_t additional_options)
193
ulong additional_options)
192
195
SELECT_LEX *lex_select_save= thd_arg->lex->current_select;
193
196
SELECT_LEX *sl, *first_sl= first_select();
194
197
select_result *tmp_result;
195
198
bool is_union_select;
196
Table *empty_table= 0;
199
TABLE *empty_table= 0;
198
201
describe= test(additional_options & SELECT_DESCRIBE);
266
269
can_skip_order_by= is_union_select && !(sl->braces && sl->explicit_limit);
268
271
saved_error= join->prepare(&sl->ref_pointer_array,
269
(TableList*) sl->table_list.first,
272
(TABLE_LIST*) sl->table_list.first,
272
275
(can_skip_order_by ? 0 :
273
276
sl->order_list.elements) +
274
277
sl->group_list.elements,
275
278
can_skip_order_by ?
276
(order_st*) 0 : (order_st *)sl->order_list.first,
277
(order_st*) sl->group_list.first,
279
(ORDER*) 0 : (ORDER *)sl->order_list.first,
280
(ORDER*) sl->group_list.first,
279
(is_union_select ? (order_st*) 0 :
280
(order_st*) thd_arg->lex->proc_list.first),
282
(is_union_select ? (ORDER*) 0 :
283
(ORDER*) thd_arg->lex->proc_list.first),
282
285
/* There are no * in the statement anymore (for PS) */
283
286
sl->with_wild= 0;
357
360
if (union_result->create_result_table(thd, &types, test(union_distinct),
358
361
create_options, "", false))
360
memset(&result_table_list, 0, sizeof(result_table_list));
363
bzero((char*) &result_table_list, sizeof(result_table_list));
361
364
result_table_list.db= (char*) "";
362
365
result_table_list.table_name= result_table_list.alias= (char*) "union";
363
366
result_table_list.table= table= union_result->table;
377
assert(thd->stmt_arena->is_conventional() == false);
375
379
We're in execution of a prepared statement or stored procedure:
376
380
reset field items to point at fields from the created temporary table.
382
table->reset_item_list(&item_list);
448
452
(select_limit_cnt == HA_POS_ERROR || sl->braces) ?
449
453
sl->options & ~OPTION_FOUND_ROWS : sl->options | found_rows_for_union;
451
/* dump_TableList_struct(select_lex, select_lex->leaf_tables); */
455
/* dump_TABLE_LIST_struct(select_lex, select_lex->leaf_tables); */
452
456
if (sl->join->flatten_subqueries())
455
/* dump_TableList_struct(select_lex, select_lex->leaf_tables); */
459
/* dump_TABLE_LIST_struct(select_lex, select_lex->leaf_tables); */
456
460
saved_error= sl->join->optimize();
458
462
if (!saved_error)
542
546
&result_table_list,
543
547
0, item_list, NULL,
544
548
global_parameters->order_list.elements,
545
(order_st*)global_parameters->order_list.first,
546
(order_st*) NULL, NULL, (order_st*) NULL,
549
(ORDER*)global_parameters->order_list.first,
550
(ORDER*) NULL, NULL, (ORDER*) NULL,
547
551
fake_select_lex->options | SELECT_NO_UNLOCK,
548
552
result, this, fake_select_lex);
565
569
&result_table_list,
566
570
0, item_list, NULL,
567
571
global_parameters->order_list.elements,
568
(order_st*)global_parameters->order_list.first,
569
(order_st*) NULL, NULL, (order_st*) NULL,
572
(ORDER*)global_parameters->order_list.first,
573
(ORDER*) NULL, NULL, (ORDER*) NULL,
570
574
fake_select_lex->options | SELECT_NO_UNLOCK,
571
575
result, this, fake_select_lex);
628
632
error|= fake_select_lex->cleanup();
629
633
if (fake_select_lex->order_list.elements)
632
for (ord= (order_st*)fake_select_lex->order_list.first; ord; ord= ord->next)
636
for (ord= (ORDER*)fake_select_lex->order_list.first; ord; ord= ord->next)
633
637
(*ord->item)->cleanup();