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"
28
#include <drizzled/optimizer/position.h>
29
#include <drizzled/optimizer/sargable_param.h>
31
30
#include "drizzled/join_cache.h"
32
31
#include "drizzled/join_table.h"
39
36
class select_result;
45
42
/* PREV_BITS only used in sql_select.cc */
46
43
#define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1))
45
#include <plugin/myisam/myisam.h>
46
#include <drizzled/sql_array.h>
48
48
/* Values in optimize */
49
49
#define KEY_OPTIMIZE_EXISTS 1
50
50
#define KEY_OPTIMIZE_REF_OR_NULL 2
55
Table *table; /**< Pointer to the table this key belongs to */
56
Item *val; /**< or value if no field */
57
table_map used_tables;
60
uint32_t optimize; /**< 0, or KEY_OPTIMIZE_* */
61
key_part_map keypart_map;
62
ha_rows ref_table_rows;
64
If true, the comparison this value was created from will not be
65
satisfied if val has NULL 'value'.
69
!NULL - This KeyUse was created from an equality that was wrapped into
70
an Item_func_trig_cond. This means the equality (and validity of
71
this KeyUse element) can be turned on and off. The on/off state
72
is indicted by the pointed value:
73
*cond_guard == true <=> equality condition is on
74
*cond_guard == false <=> equality condition is off
76
NULL - Otherwise (the source equality can't be turned off)
54
83
enum_nested_loop_state sub_select_cache(JOIN *join, JoinTable *join_tab, bool end_of_records);
144
166
List<Item> &res_all_fields,
145
167
uint32_t elements,
146
168
List<Item> &all_fields);
169
void select_describe(JOIN *join, bool need_tmp_table,bool need_order, bool distinct, const char *message= NULL);
147
170
bool change_group_ref(Session *session, Item_func *expr, order_st *group_list, bool *changed);
148
171
bool check_interleaving_with_nj(JoinTable *last, JoinTable *next);
150
int join_read_const_table(JoinTable *tab, optimizer::Position *pos);
173
int join_read_const_table(JoinTable *tab, drizzled::optimizer::Position *pos);
151
174
int join_read_system(JoinTable *tab);
152
175
int join_read_const(JoinTable *tab);
153
176
int join_read_key(JoinTable *tab);
172
195
void calc_used_field_length(Session *, JoinTable *join_tab);
173
196
StoredKey *get_store_key(Session *session,
174
optimizer::KeyUse *keyuse,
175
198
table_map used_tables,
176
199
KEY_PART_INFO *key_part,
177
200
unsigned char *key_buff,
178
201
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);
202
extern "C" int join_tab_cmp(const void* ptr1, const void* ptr2);
203
extern "C" int join_tab_cmp_straight(const void* ptr1, const void* ptr2);
181
204
void push_index_cond(JoinTable *tab, uint32_t keyno, bool other_tbls_ok);
182
205
void add_not_null_conds(JOIN *join);
183
206
uint32_t max_part_bit(key_part_map bits);
189
212
List<Item> &all_fields,
190
213
bool *all_order_by_fields_used);
191
214
bool eq_ref_table(JOIN *join, order_st *start_order, JoinTable *tab);
215
int join_tab_cmp(const void* ptr1, const void* ptr2);
192
216
int remove_dup_with_compare(Session *session, Table *table, Field **first_field, uint32_t offset, Item *having);
193
217
int remove_dup_with_hash_index(Session *session,
205
229
table_map normal_tables,
206
230
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);
231
std::vector<drizzled::optimizer::SargableParam> &sargables);
232
ha_rows get_quick_record_count(Session *session, SQL_SELECT *select, Table *table, const key_map *keys,ha_rows limit);
209
233
void optimize_keyuse(JOIN *join, DYNAMIC_ARRAY *keyuse_array);
210
234
void add_group_and_distinct_keys(JOIN *join, JoinTable *join_tab);
211
235
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
236
// Create list for using with tempory table
219
237
void init_tmptable_sum_functions(Item_sum **func);
220
238
void update_tmptable_sum_func(Item_sum **func,Table *tmp_table);
221
239
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??? */
240
bool create_ref_for_key(JOIN *join, JoinTable *j, KeyUse *org_keyuse, table_map used_tables);
242
/* functions from opt_sum.cc */
243
bool simple_pred(Item_func *func_item, Item **args, bool *inv_order);
244
int opt_sum_query(TableList *tables, List<Item> &all_fields,COND *conds);
246
/* from sql_delete.cc, used by opt_range.cc */
247
extern "C" int refpos_order_cmp(void* arg, const void *a,const void *b);
230
249
#include "drizzled/stored_key.h"
235
251
bool cp_buffer_from_ref(Session *session, table_reference_st *ref);
236
252
int safe_index_read(JoinTable *tab);
237
253
COND *remove_eq_conds(Session *session, COND *cond, Item::cond_result *cond_value);