25
25
#include "drizzled/field/varstring.h"
26
26
#include "drizzled/item/null.h"
27
27
#include <drizzled/enum_nested_loop_state.h>
28
#include "drizzled/optimizer/position.h"
29
#include "drizzled/optimizer/sargable_param.h"
30
#include "drizzled/optimizer/key_use.h"
31
28
#include "drizzled/join_cache.h"
32
29
#include "drizzled/join_table.h"
39
32
class select_result;
45
38
/* PREV_BITS only used in sql_select.cc */
46
39
#define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1))
41
#include <plugin/myisam/myisam.h>
42
#include <drizzled/sql_array.h>
48
44
/* Values in optimize */
49
45
#define KEY_OPTIMIZE_EXISTS 1
50
46
#define KEY_OPTIMIZE_REF_OR_NULL 2
51
Table *table; /**< Pointer to the table this key belongs to */
52
Item *val; /**< or value if no field */
53
table_map used_tables;
56
uint32_t optimize; /**< 0, or KEY_OPTIMIZE_* */
57
key_part_map keypart_map;
58
ha_rows ref_table_rows;
60
If true, the comparison this value was created from will not be
61
satisfied if val has NULL 'value'.
65
!NULL - This KeyUse was created from an equality that was wrapped into
66
an Item_func_trig_cond. This means the equality (and validity of
67
this KeyUse element) can be turned on and off. The on/off state
68
is indicted by the pointed value:
69
*cond_guard == true <=> equality condition is on
70
*cond_guard == false <=> equality condition is off
72
NULL - Otherwise (the source equality can't be turned off)
54
79
enum_nested_loop_state sub_select_cache(JOIN *join, JoinTable *join_tab, bool end_of_records);
56
81
enum_nested_loop_state end_send_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
57
82
enum_nested_loop_state end_write_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
85
* Information about a position of table within a join order. Used in join
99
use_insideout_scan(false)
103
* Determine whether the table this particular position is representing in
104
* the query plan is a const table or not. A constant table is defined as
105
* (taken from the MySQL optimizer internals document on MySQL forge):
107
* 1) A table with zero rows, or with only one row
108
* 2) A table expression that is restricted with a WHERE condition
110
* Based on the definition above, when records_read is set to 1.0 in the
111
* Position class, it infers that this position in the partial plan
112
* represents a const table.
114
* @return true if this position represents a const table; false otherwise
116
bool isConstTable() const
118
return (records_read < 2.0);
122
The "fanout": number of output rows that will be produced (after
123
pushed down selection condition is applied) per each row combination of
124
previous tables. The value is an in-precise estimate.
129
Cost accessing the table in course of the entire complete join execution,
130
i.e. cost of one access method use (e.g. 'range' or 'ref' scan ) times
131
number the access method will be invoked.
137
NULL - 'index' or 'range' or 'index_merge' or 'ALL' access is used.
138
Other - [eq_]ref[_or_null] access is used. Pointer to {t.keypart1 = expr}
142
/** If ref-based access is used: bitmap of tables this table depends on */
143
table_map ref_depend_map;
145
bool use_insideout_scan;
59
148
typedef struct st_rollup
61
150
enum State { STATE_NONE, STATE_INITED, STATE_READY };
65
154
List<Item> *fields;
68
} /* namespace drizzled */
70
/** @TODO why is this in the middle of the file??? */
72
157
#include "drizzled/join.h"
159
typedef struct st_select_check {
160
uint32_t const_ref,reg_ref;
164
This structure is used to collect info on potentially sargable
165
predicates in order to check whether they become sargable after
166
reading const tables.
167
We form a bitmap of indexes that can be used for sargable predicates.
168
Only such indexes are involved in range analysis.
170
typedef struct st_sargable_param
172
Field *field; /* field against which to check sargability */
173
Item **arg_value; /* values of potential keys for lookups */
174
uint32_t num_values; /* number of values in the above array */
178
* Structure used when finding key fields
180
typedef struct key_field_t
183
Item *val; /**< May be empty if diff constant */
185
uint32_t optimize; /**< KEY_OPTIMIZE_* */
188
If true, the condition this struct represents will not be satisfied
192
bool *cond_guard; /**< @see KeyUse::cond_guard */
77
195
/*****************************************************************************
78
196
Make som simple condition optimization:
144
262
List<Item> &res_all_fields,
145
263
uint32_t elements,
146
264
List<Item> &all_fields);
265
void select_describe(JOIN *join, bool need_tmp_table,bool need_order, bool distinct, const char *message= NULL);
147
266
bool change_group_ref(Session *session, Item_func *expr, order_st *group_list, bool *changed);
148
267
bool check_interleaving_with_nj(JoinTable *last, JoinTable *next);
150
int join_read_const_table(JoinTable *tab, optimizer::Position *pos);
269
int join_read_const_table(JoinTable *tab, Position *pos);
151
270
int join_read_system(JoinTable *tab);
152
271
int join_read_const(JoinTable *tab);
153
272
int join_read_key(JoinTable *tab);
172
291
void calc_used_field_length(Session *, JoinTable *join_tab);
173
292
StoredKey *get_store_key(Session *session,
174
optimizer::KeyUse *keyuse,
175
294
table_map used_tables,
176
295
KEY_PART_INFO *key_part,
177
296
unsigned char *key_buff,
178
297
uint32_t maybe_null);
179
int join_tab_cmp(const void* ptr1, const void* ptr2);
180
int join_tab_cmp_straight(const void* ptr1, const void* ptr2);
298
extern "C" int join_tab_cmp(const void* ptr1, const void* ptr2);
299
extern "C" int join_tab_cmp_straight(const void* ptr1, const void* ptr2);
181
300
void push_index_cond(JoinTable *tab, uint32_t keyno, bool other_tbls_ok);
182
301
void add_not_null_conds(JOIN *join);
183
302
uint32_t max_part_bit(key_part_map bits);
189
308
List<Item> &all_fields,
190
309
bool *all_order_by_fields_used);
191
310
bool eq_ref_table(JOIN *join, order_st *start_order, JoinTable *tab);
311
int join_tab_cmp(const void* ptr1, const void* ptr2);
192
312
int remove_dup_with_compare(Session *session, Table *table, Field **first_field, uint32_t offset, Item *having);
193
313
int remove_dup_with_hash_index(Session *session,
205
325
table_map normal_tables,
206
326
Select_Lex *select_lex,
207
std::vector<optimizer::SargableParam> &sargables);
208
ha_rows get_quick_record_count(Session *session, optimizer::SqlSelect *select, Table *table, const key_map *keys,ha_rows limit);
327
SARGABLE_PARAM **sargables);
328
ha_rows get_quick_record_count(Session *session, SQL_SELECT *select, Table *table, const key_map *keys,ha_rows limit);
209
329
void optimize_keyuse(JOIN *join, DYNAMIC_ARRAY *keyuse_array);
210
330
void add_group_and_distinct_keys(JOIN *join, JoinTable *join_tab);
211
331
void read_cached_record(JoinTable *tab);
212
bool mysql_select(Session *session, Item ***rref_pointer_array,
213
TableList *tables, uint32_t wild_num, List<Item> &list,
214
COND *conds, uint32_t og_num, order_st *order, order_st *group,
215
Item *having, uint64_t select_type,
216
select_result *result, Select_Lex_Unit *unit,
217
Select_Lex *select_lex);
218
332
// Create list for using with tempory table
219
333
void init_tmptable_sum_functions(Item_sum **func);
220
334
void update_tmptable_sum_func(Item_sum **func,Table *tmp_table);
221
335
bool only_eq_ref_tables(JOIN *join, order_st *order, table_map tables);
222
bool create_ref_for_key(JOIN *join, JoinTable *j,
223
optimizer::KeyUse *org_keyuse,
224
table_map used_tables);
226
} /* namespace drizzled */
228
/** @TODO why is this in the middle of the file??? */
336
bool create_ref_for_key(JOIN *join, JoinTable *j, KeyUse *org_keyuse, table_map used_tables);
338
/* functions from opt_sum.cc */
339
bool simple_pred(Item_func *func_item, Item **args, bool *inv_order);
340
int opt_sum_query(TableList *tables, List<Item> &all_fields,COND *conds);
342
/* from sql_delete.cc, used by opt_range.cc */
343
extern "C" int refpos_order_cmp(void* arg, const void *a,const void *b);
230
345
#include "drizzled/stored_key.h"
235
347
bool cp_buffer_from_ref(Session *session, table_reference_st *ref);
236
348
int safe_index_read(JoinTable *tab);
237
349
COND *remove_eq_conds(Session *session, COND *cond, Item::cond_result *cond_value);