22 #include <drizzled/cached_item.h>
23 #include <drizzled/field/varstring.h>
24 #include <drizzled/item/null.h>
25 #include <drizzled/enum_nested_loop_state.h>
26 #include <drizzled/optimizer/position.h>
27 #include <drizzled/optimizer/sargable_param.h>
28 #include <drizzled/optimizer/key_use.h>
29 #include <drizzled/join_cache.h>
31 #include <drizzled/records.h>
32 #include <drizzled/stored_key.h>
43 #define PREV_BITS(type,A) ((type) (((type) 1 << (A)) -1))
46 #define KEY_OPTIMIZE_EXISTS 1
47 #define KEY_OPTIMIZE_REF_OR_NULL 2
57 enum State { STATE_NONE, STATE_INITED, STATE_READY };
63 ref_pointer_arrays(NULL),
69 Item ***in_ref_pointer_arrays,
73 null_items(in_null_items),
74 ref_pointer_arrays(in_ref_pointer_arrays),
78 State getState()
const
83 void setState(State in_state)
95 null_items= in_null_items;
98 Item ***getRefPointerArrays()
const
100 return ref_pointer_arrays;
103 void setRefPointerArrays(
Item ***in_ref_pointer_arrays)
105 ref_pointer_arrays= in_ref_pointer_arrays;
121 Item ***ref_pointer_arrays;
142 typedef std::pair<Item*, Item_func*> COND_CMP;
144 void TEST_join(Join *join);
148 Table *
create_tmp_table(Session *session,Tmp_Table_Param *param,List<Item> &fields,
149 Order *group,
bool distinct,
bool save_sum_fields,
150 uint64_t select_options, ha_rows rows_limit,
153 List<Item> &fields,
bool reset_with_sum_func);
155 Item **ref_pointer_array,
156 List<Item> &new_list1, List<Item> &new_list2,
157 uint32_t elements, List<Item> &fields);
159 bool copy_funcs(Item **func_ptr,
const Session *session);
161 const char *name, Table *table,
162 Item_field *item, uint32_t convert_blob_length);
163 bool test_if_ref(Item_field *left_item,Item *right_item);
164 COND *optimize_cond(Join *join, COND *conds, List<TableList> *join_list, Item::cond_result *cond_value);
165 COND *make_cond_for_table(COND *cond,table_map table, table_map used_table,
bool exclude_expensive_cond);
170 bool test_if_skip_sort_order(JoinTable *tab,Order *order,ha_rows select_limit,
bool no_changes,
const key_map *map);
172 Item **ref_pointer_array,
176 bool *all_order_by_fields_used);
179 Item **ref_pointer_array,
180 List<Item> &res_selected_fields,
181 List<Item> &res_all_fields,
183 List<Item> &all_fields);
184 int do_select(Join *join, List<Item> *fields, Table *tmp_table);
186 int create_sort_index(Session *session, Join *join, Order *order, ha_rows filesort_limit, ha_rows select_limit,
bool is_order_by);
187 void save_index_subquery_explain_info(JoinTable *join_tab, Item* where);
190 bool init_sum_functions(Item_sum **func, Item_sum **end);
191 bool update_sum_func(Item_sum **func);
194 Item **ref_pointer_array,
195 List<Item> &res_selected_fields,
196 List<Item> &res_all_fields,
198 List<Item> &all_fields);
199 bool change_group_ref(Session *session, Item_func *expr, Order *group_list,
bool *changed);
203 int join_read_key(JoinTable *tab);
204 int join_read_always_key(JoinTable *tab);
206 int join_no_more_records(ReadRecord *info);
207 int join_read_next(ReadRecord *info);
208 int join_read_next_different(ReadRecord *info);
209 int join_init_quick_read_record(JoinTable *tab);
210 int init_read_record_seq(JoinTable *tab);
211 int test_if_quick_select(JoinTable *tab);
212 int join_init_read_record(JoinTable *tab);
213 int join_read_first(JoinTable *tab);
214 int join_read_next_same(ReadRecord *info);
215 int join_read_next_same_diff(ReadRecord *info);
216 int join_read_last(JoinTable *tab);
217 int join_read_prev_same(ReadRecord *info);
218 int join_read_prev(ReadRecord *info);
220 int join_read_next_same_or_null(ReadRecord *info);
223 StoredKey *get_store_key(Session *session,
224 optimizer::KeyUse *keyuse,
225 table_map used_tables,
226 KeyPartInfo *key_part,
227 unsigned char *key_buff,
228 uint32_t maybe_null);
231 void push_index_cond(JoinTable *tab, uint32_t keyno,
bool other_tbls_ok);
232 void add_not_null_conds(Join *join);
234 COND *add_found_match_trig_cond(JoinTable *tab, COND *cond, JoinTable *root_tab);
235 bool eq_ref_table(Join *join, Order *start_order, JoinTable *tab);
236 int remove_dup_with_compare(Session *session, Table *table, Field **first_field, uint32_t offset, Item *having);
239 uint32_t field_count,
244 DYNAMIC_ARRAY *keyuse,
249 table_map normal_tables,
250 Select_Lex *select_lex,
251 std::vector<optimizer::SargableParam> &sargables);
252 ha_rows get_quick_record_count(Session *session, optimizer::SqlSelect *select, Table *table,
const key_map *keys,ha_rows limit);
255 void read_cached_record(JoinTable *tab);
256 bool select_query(Session *session, Item ***rref_pointer_array,
257 TableList *tables, uint32_t wild_num, List<Item> &list,
258 COND *conds, uint32_t og_num, Order *order, Order *group,
259 Item *having, uint64_t select_type,
260 select_result *result, Select_Lex_Unit *unit,
261 Select_Lex *select_lex);
263 void init_tmptable_sum_functions(Item_sum **func);
265 bool only_eq_ref_tables(Join *join, Order *order, table_map tables);
266 bool create_ref_for_key(Join *join, JoinTable *j,
267 optimizer::KeyUse *org_keyuse,
268 table_map used_tables);
270 bool cp_buffer_from_ref(Session *session, table_reference_st *ref);
271 int safe_index_read(JoinTable *tab);
272 COND *
remove_eq_conds(Session *session, COND *cond, Item::cond_result *cond_value);
273 int test_if_item_cache_changed(List<Cached_item> &list);
275 void print_join(Session *session, String *str, List<TableList> *tables);