49
49
#define KEY_OPTIMIZE_EXISTS 1
50
50
#define KEY_OPTIMIZE_REF_OR_NULL 2
54
enum_nested_loop_state sub_select_cache(JOIN *join, JoinTable *join_tab, bool end_of_records);
55
enum_nested_loop_state sub_select(JOIN *join,JoinTable *join_tab, bool end_of_records);
56
enum_nested_loop_state end_send_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
57
enum_nested_loop_state end_write_group(JOIN *join, JoinTable *join_tab, bool end_of_records);
54
enum_nested_loop_state sub_select_cache(Join *join, JoinTable *join_tab, bool end_of_records);
55
enum_nested_loop_state sub_select(Join *join,JoinTable *join_tab, bool end_of_records);
56
enum_nested_loop_state end_send_group(Join *join, JoinTable *join_tab, bool end_of_records);
57
enum_nested_loop_state end_write_group(Join *join, JoinTable *join_tab, bool end_of_records);
59
59
typedef struct st_rollup
88
88
COND_CMP(Item *a,Item_func *b) :and_level(a),cmp_func(b) {}
91
void TEST_join(JOIN *join);
91
void TEST_join(Join *join);
93
93
/* Extern functions in sql_select.cc */
94
94
bool store_val_in_field(Field *field, Item *val, enum_check_fields check_flag);
95
95
Table *create_tmp_table(Session *session,Tmp_Table_Param *param,List<Item> &fields,
96
order_st *group, bool distinct, bool save_sum_fields,
96
Order *group, bool distinct, bool save_sum_fields,
97
97
uint64_t select_options, ha_rows rows_limit,
98
98
const char* alias);
99
void free_tmp_table(Session *session, Table *entry);
100
99
void count_field_types(Select_Lex *select_lex, Tmp_Table_Param *param,
101
100
List<Item> &fields, bool reset_with_sum_func);
102
101
bool setup_copy_fields(Session *session, Tmp_Table_Param *param,
109
108
const char *name, Table *table,
110
109
Item_field *item, uint32_t convert_blob_length);
111
110
bool test_if_ref(Item_field *left_item,Item *right_item);
112
COND *optimize_cond(JOIN *join, COND *conds, List<TableList> *join_list, Item::cond_result *cond_value);
111
COND *optimize_cond(Join *join, COND *conds, List<TableList> *join_list, Item::cond_result *cond_value);
113
112
COND *make_cond_for_table(COND *cond,table_map table, table_map used_table, bool exclude_expensive_cond);
114
113
COND* substitute_for_best_equal_field(COND *cond, COND_EQUAL *cond_equal, void *table_join_idx);
115
114
bool list_contains_unique_index(Table *table, bool (*find_func) (Field *, void *), void *data);
116
115
bool find_field_in_order_list (Field *field, void *data);
117
116
bool find_field_in_item_list (Field *field, void *data);
118
bool test_if_skip_sort_order(JoinTable *tab,order_st *order,ha_rows select_limit, bool no_changes, const key_map *map);
119
order_st *create_distinct_group(Session *session,
117
bool test_if_skip_sort_order(JoinTable *tab,Order *order,ha_rows select_limit, bool no_changes, const key_map *map);
118
Order *create_distinct_group(Session *session,
120
119
Item **ref_pointer_array,
121
order_st *order_list,
122
121
List<Item> &fields,
124
123
bool *all_order_by_fields_used);
129
128
List<Item> &res_all_fields,
130
129
uint32_t elements,
131
130
List<Item> &all_fields);
132
int do_select(JOIN *join, List<Item> *fields, Table *tmp_table);
131
int do_select(Join *join, List<Item> *fields, Table *tmp_table);
133
132
bool const_expression_in_where(COND *conds,Item *item, Item **comp_item);
134
int create_sort_index(Session *session, JOIN *join, order_st *order, ha_rows filesort_limit, ha_rows select_limit, bool is_order_by);
133
int create_sort_index(Session *session, Join *join, Order *order, ha_rows filesort_limit, ha_rows select_limit, bool is_order_by);
135
134
void save_index_subquery_explain_info(JoinTable *join_tab, Item* where);
136
135
Item *remove_additional_cond(Item* conds);
137
136
bool setup_sum_funcs(Session *session, Item_sum **func_ptr);
144
143
List<Item> &res_all_fields,
145
144
uint32_t elements,
146
145
List<Item> &all_fields);
147
bool change_group_ref(Session *session, Item_func *expr, order_st *group_list, bool *changed);
148
bool check_interleaving_with_nj(JoinTable *last, JoinTable *next);
146
bool change_group_ref(Session *session, Item_func *expr, Order *group_list, bool *changed);
147
bool check_interleaving_with_nj(JoinTable *next);
150
149
int join_read_const_table(JoinTable *tab, optimizer::Position *pos);
151
150
int join_read_system(JoinTable *tab);
153
152
int join_read_key(JoinTable *tab);
154
153
int join_read_always_key(JoinTable *tab);
155
154
int join_read_last_key(JoinTable *tab);
156
int join_no_more_records(READ_RECORD *info);
157
int join_read_next(READ_RECORD *info);
158
int join_read_next_different(READ_RECORD *info);
155
int join_no_more_records(ReadRecord *info);
156
int join_read_next(ReadRecord *info);
157
int join_read_next_different(ReadRecord *info);
159
158
int join_init_quick_read_record(JoinTable *tab);
160
159
int init_read_record_seq(JoinTable *tab);
161
160
int test_if_quick_select(JoinTable *tab);
162
161
int join_init_read_record(JoinTable *tab);
163
162
int join_read_first(JoinTable *tab);
164
int join_read_next_same(READ_RECORD *info);
165
int join_read_next_same_diff(READ_RECORD *info);
163
int join_read_next_same(ReadRecord *info);
164
int join_read_next_same_diff(ReadRecord *info);
166
165
int join_read_last(JoinTable *tab);
167
int join_read_prev_same(READ_RECORD *info);
168
int join_read_prev(READ_RECORD *info);
166
int join_read_prev_same(ReadRecord *info);
167
int join_read_prev(ReadRecord *info);
169
168
int join_read_always_key_or_null(JoinTable *tab);
170
int join_read_next_same_or_null(READ_RECORD *info);
169
int join_read_next_same_or_null(ReadRecord *info);
172
171
void calc_used_field_length(Session *, JoinTable *join_tab);
173
172
StoredKey *get_store_key(Session *session,
174
173
optimizer::KeyUse *keyuse,
175
174
table_map used_tables,
176
KEY_PART_INFO *key_part,
175
KeyPartInfo *key_part,
177
176
unsigned char *key_buff,
178
177
uint32_t maybe_null);
179
178
int join_tab_cmp(const void* ptr1, const void* ptr2);
180
179
int join_tab_cmp_straight(const void* ptr1, const void* ptr2);
181
180
void push_index_cond(JoinTable *tab, uint32_t keyno, bool other_tbls_ok);
182
void add_not_null_conds(JOIN *join);
181
void add_not_null_conds(Join *join);
183
182
uint32_t max_part_bit(key_part_map bits);
184
183
COND *add_found_match_trig_cond(JoinTable *tab, COND *cond, JoinTable *root_tab);
185
order_st *create_distinct_group(Session *session,
184
Order *create_distinct_group(Session *session,
186
185
Item **ref_pointer_array,
188
187
List<Item> &fields,
189
188
List<Item> &all_fields,
190
189
bool *all_order_by_fields_used);
191
bool eq_ref_table(JOIN *join, order_st *start_order, JoinTable *tab);
190
bool eq_ref_table(Join *join, Order *start_order, JoinTable *tab);
192
191
int remove_dup_with_compare(Session *session, Table *table, Field **first_field, uint32_t offset, Item *having);
193
192
int remove_dup_with_hash_index(Session *session,
206
205
Select_Lex *select_lex,
207
206
std::vector<optimizer::SargableParam> &sargables);
208
207
ha_rows get_quick_record_count(Session *session, optimizer::SqlSelect *select, Table *table, const key_map *keys,ha_rows limit);
209
void optimize_keyuse(JOIN *join, DYNAMIC_ARRAY *keyuse_array);
210
void add_group_and_distinct_keys(JOIN *join, JoinTable *join_tab);
208
void optimize_keyuse(Join *join, DYNAMIC_ARRAY *keyuse_array);
209
void add_group_and_distinct_keys(Join *join, JoinTable *join_tab);
211
210
void read_cached_record(JoinTable *tab);
212
211
bool mysql_select(Session *session, Item ***rref_pointer_array,
213
212
TableList *tables, uint32_t wild_num, List<Item> &list,
214
COND *conds, uint32_t og_num, order_st *order, order_st *group,
213
COND *conds, uint32_t og_num, Order *order, Order *group,
215
214
Item *having, uint64_t select_type,
216
215
select_result *result, Select_Lex_Unit *unit,
217
216
Select_Lex *select_lex);
218
217
// Create list for using with tempory table
219
218
void init_tmptable_sum_functions(Item_sum **func);
220
219
void update_tmptable_sum_func(Item_sum **func,Table *tmp_table);
221
bool only_eq_ref_tables(JOIN *join, order_st *order, table_map tables);
222
bool create_ref_for_key(JOIN *join, JoinTable *j,
220
bool only_eq_ref_tables(Join *join, Order *order, table_map tables);
221
bool create_ref_for_key(Join *join, JoinTable *j,
223
222
optimizer::KeyUse *org_keyuse,
224
223
table_map used_tables);