25
25
#pragma interface /* gcc class implementation */
28
/* PREV_BITS only used in sql_select.cc */
29
#define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1))
28
31
#include <storage/myisam/myisam.h>
30
33
/* Values in optimize */
67
70
typedef struct st_table_ref
70
uint key_parts; ///< num of ...
71
uint key_length; ///< length of key_buff
73
uchar *key_buff; ///< value to look for with key
74
uchar *key_buff2; ///< key_buff+key_length
73
uint32_t key_parts; ///< num of ...
74
uint32_t key_length; ///< length of key_buff
75
int32_t key; ///< key no
76
unsigned char *key_buff; ///< value to look for with key
77
unsigned char *key_buff2; ///< key_buff+key_length
75
78
store_key **key_copy; //
76
79
Item **items; ///< val()'s for each keypart
93
96
key_part_map null_rejecting;
94
97
table_map depend_map; ///< Table depends on these tables.
95
98
/* null byte position in the key_buf. Used for REF_OR_NULL optimization */
99
unsigned char *null_ref_key;
99
102
true <=> disable the "cache" as doing lookup with the same key value may
113
116
Where source data is located (i.e. this points to somewhere in
114
117
tableX->record[0])
117
uint length; /* Length of data at *str, in bytes */
118
uint blob_length; /* Valid IFF blob_field != 0 */
120
uint32_t length; /* Length of data at *str, in bytes */
121
uint32_t blob_length; /* Valid IFF blob_field != 0 */
119
122
Field_blob *blob_field;
120
123
bool strip; /* true <=> Strip endspaces ?? */
122
TABLE *get_rowid; /* _ != NULL <=> */
125
Table *get_rowid; /* _ != NULL <=> */
126
129
typedef struct st_join_cache
129
uchar *pos; /* Start of free space in the buffer */
131
uint records; /* # of row cominations currently stored in the cache */
132
unsigned char *pos; /* Start of free space in the buffer */
134
uint32_t records; /* # of row cominations currently stored in the cache */
135
138
Number of fields (i.e. cache_field objects). Those correspond to table
136
139
columns, and there are also special fields for
264
267
Embedding SJ-nest (may be not the direct parent), or NULL if none.
265
268
This variable holds the result of table pullout.
267
TABLE_LIST *emb_sj_nest;
270
TableList *emb_sj_nest;
269
272
/* Variables for semi-join duplicate elimination */
270
273
SJ_TMP_TABLE *flush_weedout_table;
367
Describes use of one temporary table to weed out join duplicates.
371
- create a temp table
372
- when we reach the weed-out tab, walk through rowid-ed tabs and
374
For each table we need
379
class SJ_TMP_TABLE : public Sql_alloc
382
/* Array of pointers to tables that should be "used" */
400
MI_COLUMNDEF *start_recinfo;
401
MI_COLUMNDEF *recinfo;
403
/* Pointer to next table (next->start_idx > this->end_idx) */
408
369
class JOIN :public Sql_alloc
410
371
JOIN(const JOIN &rhs); /**< not implemented */
413
374
JOIN_TAB *join_tab,**best_ref;
414
375
JOIN_TAB **map2table; ///< mapping between table indexes and JOIN_TABs
415
376
JOIN_TAB *join_tab_save; ///< saved join_tab for subquery reexecution
416
TABLE **table,**all_tables;
377
Table **table,**all_tables;
418
379
The table which has an index that allows to produce the requried ordering.
419
380
A special value of 0x1 means that the ordering will be produced by
420
381
passing 1st non-const table to filesort(). NULL means no such table exists.
422
TABLE *sort_by_table;
383
Table *sort_by_table;
423
384
uint tables; /**< Number of tables in the join */
424
385
uint outer_tables; /**< Number of tables that are not inside semijoin */
425
386
uint const_tables;
454
415
double best_read;
455
416
List<Item> *fields;
456
417
List<Cached_item> group_fields, group_fields_cache;
458
419
/// used to store 2 possible tmp table of SELECT
459
TABLE *exec_tmp_table1, *exec_tmp_table2;
420
Table *exec_tmp_table1, *exec_tmp_table2;
461
422
Item_sum **sum_funcs, ***sum_funcs_end;
462
423
/** second copy of sumfuncs (for queries with 2 temporary tables */
495
456
bool group_optimized_away;
498
simple_xxxxx is set if ORDER/GROUP BY doesn't include any references
459
simple_xxxxx is set if order_st/GROUP BY doesn't include any references
499
460
to other tables than the first non-constant table in the JOIN.
500
It's also set if ORDER/GROUP BY is empty.
461
It's also set if order_st/GROUP BY is empty.
502
463
bool simple_order, simple_group;
504
465
Is set only in case if we have a GROUP BY clause
505
and no ORDER BY after constant elimination of 'order'.
466
and no order_st BY after constant elimination of 'order'.
508
/** Is set if we have a GROUP BY and we have ORDER BY on a constant. */
469
/** Is set if we have a GROUP BY and we have order_st BY on a constant. */
509
470
bool skip_sort_order;
511
472
bool need_tmp, hidden_group_fields;
519
480
List<Item> &fields_list; ///< hold field list passed to mysql_select
522
ORDER *order, *group_list, *proc_param; //hold parameters of mysql_select
483
order_st *order, *group_list, *proc_param; //hold parameters of mysql_select
523
484
COND *conds; // ---"---
524
485
Item *conds_history; // store WHERE for explain
525
TABLE_LIST *tables_list; ///<hold 'tables' parameter of mysql_select
526
List<TABLE_LIST> *join_list; ///< list of joined tables in reverse order
486
TableList *tables_list; ///<hold 'tables' parameter of mysql_select
487
List<TableList> *join_list; ///< list of joined tables in reverse order
527
488
COND_EQUAL *cond_equal;
528
489
SQL_SELECT *select; ///<created in optimisation phase
529
490
JOIN_TAB *return_tab; ///<used only for outer joins
551
512
excessive memory usage.
553
514
SORT_FIELD *sortorder; // make_unireg_sortorder()
554
TABLE **table_reexec; // make_simple_join()
515
Table **table_reexec; // make_simple_join()
555
516
JOIN_TAB *join_tab_reexec; // make_simple_join()
556
517
/* end of allocation caching storage */
611
572
all_fields= fields_arg;
612
573
fields_list= fields_arg;
613
memset((char*) &keyuse, 0, sizeof(keyuse));
574
memset(&keyuse, 0, sizeof(keyuse));
614
575
tmp_table_param.init();
615
576
tmp_table_param.end_write_records= HA_POS_ERROR;
616
577
rollup.state= ROLLUP::STATE_NONE;
619
580
no_const_tables= false;
622
int prepare(Item ***rref_pointer_array, TABLE_LIST *tables, uint wind_num,
623
COND *conds, uint og_num, ORDER *order, ORDER *group,
624
Item *having, ORDER *proc_param, SELECT_LEX *select,
583
int prepare(Item ***rref_pointer_array, TableList *tables, uint wind_num,
584
COND *conds, uint og_num, order_st *order, order_st *group,
585
Item *having, order_st *proc_param, SELECT_LEX *select,
625
586
SELECT_LEX_UNIT *unit);
637
598
inline void set_items_ref_array(Item **ptr)
639
memcpy((char*) ref_pointer_array, (char*) ptr, ref_pointer_array_size);
600
memcpy(ref_pointer_array, ptr, ref_pointer_array_size);
640
601
current_ref_pointer_array= ptr;
642
603
inline void init_items_ref_array()
650
611
bool rollup_make_fields(List<Item> &all_fields, List<Item> &fields,
651
612
Item_sum ***func);
652
613
int rollup_send_data(uint idx);
653
int rollup_write_data(uint idx, TABLE *table);
614
int rollup_write_data(uint idx, Table *table);
654
615
void remove_subq_pushed_predicates(Item **where);
656
617
Release memory and, if possible, the open tables held by this execution
688
649
/* Extern functions in sql_select.cc */
689
650
bool store_val_in_field(Field *field, Item *val, enum_check_fields check_flag);
690
TABLE *create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
691
ORDER *group, bool distinct, bool save_sum_fields,
651
Table *create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
652
order_st *group, bool distinct, bool save_sum_fields,
692
653
uint64_t select_options, ha_rows rows_limit,
694
void free_tmp_table(THD *thd, TABLE *entry);
655
void free_tmp_table(THD *thd, Table *entry);
695
656
void count_field_types(SELECT_LEX *select_lex, TMP_TABLE_PARAM *param,
696
657
List<Item> &fields, bool reset_with_sum_func);
697
658
bool setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
700
661
uint elements, List<Item> &fields);
701
662
void copy_fields(TMP_TABLE_PARAM *param);
702
663
void copy_funcs(Item **func_ptr);
703
bool create_myisam_from_heap(THD *thd, TABLE *table,
704
MI_COLUMNDEF *start_recinfo,
705
MI_COLUMNDEF **recinfo,
706
int error, bool ignore_last_dupp_key_error);
707
uint find_shortest_key(TABLE *table, const key_map *usable_keys);
708
664
Field* create_tmp_field_from_field(THD *thd, Field* org_field,
709
const char *name, TABLE *table,
665
const char *name, Table *table,
710
666
Item_field *item, uint convert_blob_length);
712
668
/* functions from opt_sum.cc */
713
669
bool simple_pred(Item_func *func_item, Item **args, bool *inv_order);
714
int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds);
670
int opt_sum_query(TableList *tables, List<Item> &all_fields,COND *conds);
716
672
/* from sql_delete.cc, used by opt_range.cc */
717
673
extern "C" int refpos_order_cmp(void* arg, const void *a,const void *b);
797
753
enum store_key_result copy_inner()
799
TABLE *table= copy_field.to_field->table;
800
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table,
802
755
copy_field.do_copy(©_field);
803
dbug_tmp_restore_column_map(table->write_set, old_map);
804
756
null_key= to_field->is_null();
805
757
return err != 0 ? STORE_KEY_FATAL : STORE_KEY_OK;
824
776
enum store_key_result copy_inner()
826
TABLE *table= to_field->table;
827
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table,
829
778
int res= item->save_in_field(to_field, 1);
830
dbug_tmp_restore_column_map(table->write_set, old_map);
831
779
null_key= to_field->is_null() || item->null_value;
832
780
return (err != 0 || res > 2 ? STORE_KEY_FATAL : (store_key_result) res);
869
bool cp_buffer_from_ref(THD *thd, TABLE *table, TABLE_REF *ref);
817
bool cp_buffer_from_ref(THD *thd, TABLE_REF *ref);
870
818
bool error_if_full_join(JOIN *join);
871
int report_error(TABLE *table, int error);
872
819
int safe_index_read(JOIN_TAB *tab);
873
820
COND *remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value);
874
821
int test_if_item_cache_changed(List<Cached_item> &list);