376
389
List<Item> *fields;
380
class JOIN :public Sql_alloc
382
JOIN(const JOIN &rhs); /**< not implemented */
383
JOIN& operator=(const JOIN &rhs); /**< not implemented */
385
JOIN_TAB *join_tab,**best_ref;
386
JOIN_TAB **map2table; ///< mapping between table indexes and JOIN_TABs
387
JOIN_TAB *join_tab_save; ///< saved join_tab for subquery reexecution
388
Table **table,**all_tables;
390
The table which has an index that allows to produce the requried ordering.
391
A special value of 0x1 means that the ordering will be produced by
392
passing 1st non-const table to filesort(). NULL means no such table exists.
394
Table *sort_by_table;
395
uint tables; /**< Number of tables in the join */
396
uint32_t outer_tables; /**< Number of tables that are not inside semijoin */
397
uint32_t const_tables;
398
uint send_group_parts;
399
bool sort_and_group,first_record,full_join,group, no_field_update;
402
true when we want to resume nested loop iterations when
403
fetching data from a cursor
405
bool resume_nested_loop;
406
table_map const_table_map,found_const_table_map,outer_join;
407
ha_rows send_records,found_records,examined_rows,row_limit, select_limit;
409
Used to fetch no more than given amount of rows per one
410
fetch operation of server side cursor.
411
The value is checked in end_send and end_send_group in fashion, similar
413
- fetch_limit= HA_POS_ERROR if there is no cursor.
414
- when we open a cursor, we set fetch_limit to 0,
415
- on each fetch iteration we add num_rows to fetch to fetch_limit
418
POSITION positions[MAX_TABLES+1],best_positions[MAX_TABLES+1];
421
Bitmap of nested joins embedding the position at the end of the current
422
partial join (valid only during join optimizer run).
424
nested_join_map cur_embedding_map;
428
List<Cached_item> group_fields, group_fields_cache;
430
/// used to store 2 possible tmp table of SELECT
431
Table *exec_tmp_table1, *exec_tmp_table2;
433
Item_sum **sum_funcs, ***sum_funcs_end;
434
/** second copy of sumfuncs (for queries with 2 temporary tables */
435
Item_sum **sum_funcs2, ***sum_funcs_end2;
437
Item *tmp_having; ///< To store having when processed temporary table
438
Item *having_history; ///< Store having for explain
439
uint64_t select_options;
440
select_result *result;
441
Tmp_Table_Param tmp_table_param;
443
/// unit structure (with global parameters) for this select
444
Select_Lex_Unit *unit;
445
/// select that processed
446
Select_Lex *select_lex;
448
true <=> optimizer must not mark any table as a constant table.
449
This is needed for subqueries in form "a IN (SELECT .. UNION SELECT ..):
450
when we optimize the select that reads the results of the union from a
451
temporary table, we must not mark the temp. table as constant because
452
the number of rows in it may vary from one subquery execution to another.
454
bool no_const_tables;
456
JOIN *tmp_join; ///< copy of this JOIN to be used with temporary tables
457
ROLLUP rollup; ///< Used with rollup
459
bool select_distinct; ///< Set if SELECT DISTINCT
461
If we have the GROUP BY statement in the query,
462
but the group_list was emptied by optimizer, this
464
It happens when fields in the GROUP BY are from
467
bool group_optimized_away;
470
simple_xxxxx is set if order_st/GROUP BY doesn't include any references
471
to other tables than the first non-constant table in the JOIN.
472
It's also set if order_st/GROUP BY is empty.
474
bool simple_order, simple_group;
476
Is set only in case if we have a GROUP BY clause
477
and no order_st BY after constant elimination of 'order'.
480
/** Is set if we have a GROUP BY and we have order_st BY on a constant. */
481
bool skip_sort_order;
483
bool need_tmp, hidden_group_fields;
484
DYNAMIC_ARRAY keyuse;
485
Item::cond_result cond_value, having_value;
486
List<Item> all_fields; ///< to store all fields that used in query
487
///Above list changed to use temporary table
488
List<Item> tmp_all_fields1, tmp_all_fields2, tmp_all_fields3;
489
///Part, shared with list above, emulate following list
490
List<Item> tmp_fields_list1, tmp_fields_list2, tmp_fields_list3;
491
List<Item> &fields_list; ///< hold field list passed to mysql_select
494
order_st *order, *group_list; //hold parameters of mysql_select
495
COND *conds; // ---"---
496
Item *conds_history; // store WHERE for explain
497
TableList *tables_list; ///<hold 'tables' parameter of mysql_select
498
List<TableList> *join_list; ///< list of joined tables in reverse order
499
COND_EQUAL *cond_equal;
500
SQL_SELECT *select; ///<created in optimisation phase
501
JOIN_TAB *return_tab; ///<used only for outer joins
502
Item **ref_pointer_array; ///<used pointer reference for this select
503
// Copy of above to be used with different lists
504
Item **items0, **items1, **items2, **items3, **current_ref_pointer_array;
505
uint32_t ref_pointer_array_size; ///< size of above in bytes
506
const char *zero_result_cause; ///< not 0 if exec must return zero result
508
bool union_part; ///< this subselect is part of union
509
bool optimized; ///< flag to avoid double optimization in EXPLAIN
511
Array<Item_in_subselect> sj_subselects;
513
/* Descriptions of temporary tables used to weed-out semi-join duplicates */
514
SJ_TMP_TABLE *sj_tmp_tables;
516
table_map cur_emb_sj_nests;
519
storage for caching buffers allocated during query execution.
520
These buffers allocations need to be cached as the thread memory pool is
521
cleared only at the end of the execution of the whole query and not caching
522
allocations that occur in repetition at execution time will result in
523
excessive memory usage.
525
SORT_FIELD *sortorder; // make_unireg_sortorder()
526
Table **table_reexec; // make_simple_join()
527
JOIN_TAB *join_tab_reexec; // make_simple_join()
528
/* end of allocation caching storage */
530
JOIN(Session *session_arg, List<Item> &fields_arg, uint64_t select_options_arg,
531
select_result *result_arg)
532
:fields_list(fields_arg), sj_subselects(session_arg->mem_root, 4)
534
init(session_arg, fields_arg, select_options_arg, result_arg);
537
void init(Session *session_arg, List<Item> &fields_arg, uint64_t select_options_arg,
538
select_result *result_arg)
540
join_tab= join_tab_save= 0;
548
resume_nested_loop= false;
551
fetch_limit= HA_POS_ERROR;
558
session= session_arg;
559
sum_funcs= sum_funcs2= 0;
560
having= tmp_having= having_history= 0;
561
select_options= select_options_arg;
563
lock= session_arg->lock;
564
select_lex= 0; //for safety
566
select_distinct= test(select_options & SELECT_DISTINCT);
572
hidden_group_fields= 0; /*safety*/
576
ref_pointer_array= items0= items1= items2= items3= 0;
577
ref_pointer_array_size= 0;
578
zero_result_cause= 0;
581
group_optimized_away= 0;
583
all_fields= fields_arg;
584
if (&fields_list != &fields_arg) /* only copy if not same*/
585
fields_list= fields_arg;
586
memset(&keyuse, 0, sizeof(keyuse));
587
tmp_table_param.init();
588
tmp_table_param.end_write_records= HA_POS_ERROR;
589
rollup.state= ROLLUP::STATE_NONE;
592
no_const_tables= false;
595
int prepare(Item ***rref_pointer_array, TableList *tables, uint32_t wind_num,
596
COND *conds, uint32_t og_num, order_st *order, order_st *group,
597
Item *having, Select_Lex *select, Select_Lex_Unit *unit);
603
bool alloc_func_list();
604
bool flatten_subqueries();
605
bool setup_subquery_materialization();
606
bool make_sum_func_list(List<Item> &all_fields, List<Item> &send_fields,
607
bool before_group_by, bool recompute= false);
609
inline void set_items_ref_array(Item **ptr)
611
memcpy(ref_pointer_array, ptr, ref_pointer_array_size);
612
current_ref_pointer_array= ptr;
614
inline void init_items_ref_array()
616
items0= ref_pointer_array + all_fields.elements;
617
memcpy(items0, ref_pointer_array, ref_pointer_array_size);
618
current_ref_pointer_array= items0;
622
bool rollup_make_fields(List<Item> &all_fields, List<Item> &fields,
624
int rollup_send_data(uint32_t idx);
625
int rollup_write_data(uint32_t idx, Table *table);
626
void remove_subq_pushed_predicates(Item **where);
628
Release memory and, if possible, the open tables held by this execution
629
plan (and nested plans). It's used to release some tables before
630
the end of execution in order to increase concurrency and reduce
634
/** Cleanup this JOIN, possibly for reuse */
635
void cleanup(bool full);
637
bool save_join_tab();
638
bool init_save_join_tab();
639
bool send_row_on_empty_set()
641
return (do_send_rows && tmp_table_param.sum_func_count != 0 &&
644
bool change_result(select_result *result);
645
bool is_top_level_join() const
647
return (unit == &session->lex->unit && (unit->fake_select_lex == 0 ||
648
select_lex == unit->fake_select_lex));
392
#include "drizzled/join.h"
653
394
typedef struct st_select_check {
654
395
uint32_t const_ref,reg_ref;