49
43
/* PREV_BITS only used in sql_select.cc */
50
44
#define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1))
46
#include <plugin/myisam/myisam.h>
47
#include <drizzled/sql_array.h>
52
49
/* Values in optimize */
53
50
#define KEY_OPTIMIZE_EXISTS 1
54
51
#define KEY_OPTIMIZE_REF_OR_NULL 2
58
enum_nested_loop_state sub_select_cache(Join *join, JoinTable *join_tab, bool end_of_records);
59
enum_nested_loop_state sub_select(Join *join,JoinTable *join_tab, bool end_of_records);
60
enum_nested_loop_state end_send_group(Join *join, JoinTable *join_tab, bool end_of_records);
61
enum_nested_loop_state end_write_group(Join *join, JoinTable *join_tab, bool end_of_records);
55
enum_nested_loop_state sub_select_cache(JOIN *join, JoinTable *join_tab, bool end_of_records);
56
enum_nested_loop_state sub_select(JOIN *join,JoinTable *join_tab, bool end_of_records);
57
enum_nested_loop_state end_send_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
58
enum_nested_loop_state end_write_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
60
typedef struct st_rollup
66
62
enum State { STATE_NONE, STATE_INITED, STATE_READY };
72
ref_pointer_arrays(NULL),
76
Rollup(State in_state,
77
Item_null_result **in_null_items,
78
Item ***in_ref_pointer_arrays,
79
List<Item> *in_fields)
82
null_items(in_null_items),
83
ref_pointer_arrays(in_ref_pointer_arrays),
87
State getState() const
92
void setState(State in_state)
97
Item_null_result **getNullItems() const
102
void setNullItems(Item_null_result **in_null_items)
104
null_items= in_null_items;
107
Item ***getRefPointerArrays() const
109
return ref_pointer_arrays;
112
void setRefPointerArrays(Item ***in_ref_pointer_arrays)
114
ref_pointer_arrays= in_ref_pointer_arrays;
117
List<Item> *getFields() const
122
void setFields(List<Item> *in_fields)
129
64
Item_null_result **null_items;
130
65
Item ***ref_pointer_arrays;
131
66
List<Item> *fields;
134
} /* namespace drizzled */
136
/** @TODO why is this in the middle of the file??? */
138
69
#include "drizzled/join.h"
143
71
/*****************************************************************************
144
72
Make som simple condition optimization:
145
73
If there is a test 'field = const' change all refs to 'field' to 'const'
148
76
item->marker should be 0 for all items on entry
149
77
Return in cond_value false if condition is impossible (1 = 2)
150
78
*****************************************************************************/
151
typedef std::pair<Item*, Item_func*> COND_CMP;
82
COND_CMP(Item *a,Item_func *b) :and_level(a),cmp_func(b) {}
153
void TEST_join(Join *join);
85
void TEST_join(JOIN *join);
155
87
/* Extern functions in sql_select.cc */
156
88
bool store_val_in_field(Field *field, Item *val, enum_check_fields check_flag);
157
89
Table *create_tmp_table(Session *session,Tmp_Table_Param *param,List<Item> &fields,
158
Order *group, bool distinct, bool save_sum_fields,
90
order_st *group, bool distinct, bool save_sum_fields,
159
91
uint64_t select_options, ha_rows rows_limit,
160
92
const char* alias);
93
void free_tmp_table(Session *session, Table *entry);
161
94
void count_field_types(Select_Lex *select_lex, Tmp_Table_Param *param,
162
95
List<Item> &fields, bool reset_with_sum_func);
163
96
bool setup_copy_fields(Session *session, Tmp_Table_Param *param,
165
98
List<Item> &new_list1, List<Item> &new_list2,
166
99
uint32_t elements, List<Item> &fields);
167
100
void copy_fields(Tmp_Table_Param *param);
168
bool copy_funcs(Item **func_ptr, const Session *session);
101
void copy_funcs(Item **func_ptr);
169
102
Field* create_tmp_field_from_field(Session *session, Field* org_field,
170
103
const char *name, Table *table,
171
104
Item_field *item, uint32_t convert_blob_length);
172
105
bool test_if_ref(Item_field *left_item,Item *right_item);
173
COND *optimize_cond(Join *join, COND *conds, List<TableList> *join_list, Item::cond_result *cond_value);
106
COND *optimize_cond(JOIN *join, COND *conds, List<TableList> *join_list, Item::cond_result *cond_value);
174
107
COND *make_cond_for_table(COND *cond,table_map table, table_map used_table, bool exclude_expensive_cond);
175
108
COND* substitute_for_best_equal_field(COND *cond, COND_EQUAL *cond_equal, void *table_join_idx);
176
109
bool list_contains_unique_index(Table *table, bool (*find_func) (Field *, void *), void *data);
177
110
bool find_field_in_order_list (Field *field, void *data);
178
111
bool find_field_in_item_list (Field *field, void *data);
179
bool test_if_skip_sort_order(JoinTable *tab,Order *order,ha_rows select_limit, bool no_changes, const key_map *map);
180
Order *create_distinct_group(Session *session,
112
bool test_if_skip_sort_order(JoinTable *tab,order_st *order,ha_rows select_limit, bool no_changes, const key_map *map);
113
order_st *create_distinct_group(Session *session,
181
114
Item **ref_pointer_array,
115
order_st *order_list,
183
116
List<Item> &fields,
185
118
bool *all_order_by_fields_used);
190
123
List<Item> &res_all_fields,
191
124
uint32_t elements,
192
125
List<Item> &all_fields);
193
int do_select(Join *join, List<Item> *fields, Table *tmp_table);
126
int do_select(JOIN *join, List<Item> *fields, Table *tmp_table);
194
127
bool const_expression_in_where(COND *conds,Item *item, Item **comp_item);
195
int create_sort_index(Session *session, Join *join, Order *order, ha_rows filesort_limit, ha_rows select_limit, bool is_order_by);
128
int create_sort_index(Session *session, JOIN *join, order_st *order, ha_rows filesort_limit, ha_rows select_limit, bool is_order_by);
196
129
void save_index_subquery_explain_info(JoinTable *join_tab, Item* where);
197
130
Item *remove_additional_cond(Item* conds);
198
131
bool setup_sum_funcs(Session *session, Item_sum **func_ptr);
205
138
List<Item> &res_all_fields,
206
139
uint32_t elements,
207
140
List<Item> &all_fields);
208
bool change_group_ref(Session *session, Item_func *expr, Order *group_list, bool *changed);
209
bool check_interleaving_with_nj(JoinTable *next);
210
void update_const_equal_items(COND *cond, JoinTable *tab);
141
bool change_group_ref(Session *session, Item_func *expr, order_st *group_list, bool *changed);
142
bool check_interleaving_with_nj(JoinTable *last, JoinTable *next);
144
int join_read_const_table(JoinTable *tab, drizzled::optimizer::Position *pos);
145
int join_read_system(JoinTable *tab);
211
146
int join_read_const(JoinTable *tab);
212
147
int join_read_key(JoinTable *tab);
213
148
int join_read_always_key(JoinTable *tab);
214
149
int join_read_last_key(JoinTable *tab);
215
int join_no_more_records(ReadRecord *info);
216
int join_read_next(ReadRecord *info);
217
int join_read_next_different(ReadRecord *info);
150
int join_no_more_records(READ_RECORD *info);
151
int join_read_next(READ_RECORD *info);
152
int join_read_next_different(READ_RECORD *info);
218
153
int join_init_quick_read_record(JoinTable *tab);
219
154
int init_read_record_seq(JoinTable *tab);
220
155
int test_if_quick_select(JoinTable *tab);
221
156
int join_init_read_record(JoinTable *tab);
222
157
int join_read_first(JoinTable *tab);
223
int join_read_next_same(ReadRecord *info);
224
int join_read_next_same_diff(ReadRecord *info);
158
int join_read_next_same(READ_RECORD *info);
159
int join_read_next_same_diff(READ_RECORD *info);
225
160
int join_read_last(JoinTable *tab);
226
int join_read_prev_same(ReadRecord *info);
227
int join_read_prev(ReadRecord *info);
161
int join_read_prev_same(READ_RECORD *info);
162
int join_read_prev(READ_RECORD *info);
228
163
int join_read_always_key_or_null(JoinTable *tab);
229
int join_read_next_same_or_null(ReadRecord *info);
164
int join_read_next_same_or_null(READ_RECORD *info);
231
166
void calc_used_field_length(Session *, JoinTable *join_tab);
232
167
StoredKey *get_store_key(Session *session,
233
optimizer::KeyUse *keyuse,
168
drizzled::optimizer::KeyUse *keyuse,
234
169
table_map used_tables,
235
KeyPartInfo *key_part,
170
KEY_PART_INFO *key_part,
236
171
unsigned char *key_buff,
237
172
uint32_t maybe_null);
238
int join_tab_cmp(const void* ptr1, const void* ptr2);
239
int join_tab_cmp_straight(const void* ptr1, const void* ptr2);
173
extern "C" int join_tab_cmp(const void* ptr1, const void* ptr2);
174
extern "C" int join_tab_cmp_straight(const void* ptr1, const void* ptr2);
240
175
void push_index_cond(JoinTable *tab, uint32_t keyno, bool other_tbls_ok);
241
void add_not_null_conds(Join *join);
176
void add_not_null_conds(JOIN *join);
242
177
uint32_t max_part_bit(key_part_map bits);
243
178
COND *add_found_match_trig_cond(JoinTable *tab, COND *cond, JoinTable *root_tab);
244
bool eq_ref_table(Join *join, Order *start_order, JoinTable *tab);
179
order_st *create_distinct_group(Session *session,
180
Item **ref_pointer_array,
183
List<Item> &all_fields,
184
bool *all_order_by_fields_used);
185
bool eq_ref_table(JOIN *join, order_st *start_order, JoinTable *tab);
186
int join_tab_cmp(const void* ptr1, const void* ptr2);
245
187
int remove_dup_with_compare(Session *session, Table *table, Field **first_field, uint32_t offset, Item *having);
246
188
int remove_dup_with_hash_index(Session *session,
258
200
table_map normal_tables,
259
201
Select_Lex *select_lex,
260
std::vector<optimizer::SargableParam> &sargables);
261
ha_rows get_quick_record_count(Session *session, optimizer::SqlSelect *select, Table *table, const key_map *keys,ha_rows limit);
262
void optimize_keyuse(Join *join, DYNAMIC_ARRAY *keyuse_array);
263
void add_group_and_distinct_keys(Join *join, JoinTable *join_tab);
202
std::vector<drizzled::optimizer::SargableParam> &sargables);
203
ha_rows get_quick_record_count(Session *session, drizzled::optimizer::SqlSelect *select, Table *table, const key_map *keys,ha_rows limit);
204
void optimize_keyuse(JOIN *join, DYNAMIC_ARRAY *keyuse_array);
205
void add_group_and_distinct_keys(JOIN *join, JoinTable *join_tab);
264
206
void read_cached_record(JoinTable *tab);
265
bool select_query(Session *session, Item ***rref_pointer_array,
207
bool mysql_select(Session *session, Item ***rref_pointer_array,
266
208
TableList *tables, uint32_t wild_num, List<Item> &list,
267
COND *conds, uint32_t og_num, Order *order, Order *group,
209
COND *conds, uint32_t og_num, order_st *order, order_st *group,
268
210
Item *having, uint64_t select_type,
269
211
select_result *result, Select_Lex_Unit *unit,
270
212
Select_Lex *select_lex);
271
213
// Create list for using with tempory table
272
214
void init_tmptable_sum_functions(Item_sum **func);
273
215
void update_tmptable_sum_func(Item_sum **func,Table *tmp_table);
274
bool only_eq_ref_tables(Join *join, Order *order, table_map tables);
275
bool create_ref_for_key(Join *join, JoinTable *j,
276
optimizer::KeyUse *org_keyuse,
216
bool only_eq_ref_tables(JOIN *join, order_st *order, table_map tables);
217
bool create_ref_for_key(JOIN *join, JoinTable *j,
218
drizzled::optimizer::KeyUse *org_keyuse,
277
219
table_map used_tables);
221
#include "drizzled/stored_key.h"
279
223
bool cp_buffer_from_ref(Session *session, table_reference_st *ref);
280
224
int safe_index_read(JoinTable *tab);
281
225
COND *remove_eq_conds(Session *session, COND *cond, Item::cond_result *cond_value);