44
44
DYNAMIC_ARRAY *keyuse);
45
45
static bool update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,
46
46
JOIN_TAB *join_tab,
47
uint tables, COND *conds,
47
uint32_t tables, COND *conds,
48
48
COND_EQUAL *cond_equal,
49
49
table_map table_map, SELECT_LEX *select_lex,
50
50
st_sargable_param **sargables);
51
51
static int sort_keyuse(KEYUSE *a,KEYUSE *b);
52
static void set_position(JOIN *join,uint index,JOIN_TAB *table,KEYUSE *key);
52
static void set_position(JOIN *join,uint32_t index,JOIN_TAB *table,KEYUSE *key);
53
53
static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, KEYUSE *org_keyuse,
54
54
table_map used_tables);
55
55
static bool choose_plan(JOIN *join,table_map join_tables);
57
57
static void best_access_path(JOIN *join, JOIN_TAB *s, THD *thd,
58
table_map remaining_tables, uint idx,
58
table_map remaining_tables, uint32_t idx,
59
59
double record_count, double read_time);
60
60
static void optimize_straight_join(JOIN *join, table_map join_tables);
61
61
static bool greedy_search(JOIN *join, table_map remaining_tables,
62
uint depth, uint prune_level);
62
uint32_t depth, uint32_t prune_level);
63
63
static bool best_extension_by_limited_search(JOIN *join,
64
64
table_map remaining_tables,
65
uint idx, double record_count,
66
double read_time, uint depth,
68
static uint determine_search_depth(JOIN* join);
65
uint32_t idx, double record_count,
66
double read_time, uint32_t depth,
67
uint32_t prune_level);
68
static uint32_t determine_search_depth(JOIN* join);
69
69
static int join_tab_cmp(const void* ptr1, const void* ptr2);
70
70
static int join_tab_cmp_straight(const void* ptr1, const void* ptr2);
72
72
TODO: 'find_best' is here only temporarily until 'greedy_search' is
73
73
tested and approved.
75
static bool find_best(JOIN *join,table_map rest_tables,uint index,
75
static bool find_best(JOIN *join,table_map rest_tables,uint32_t index,
76
76
double record_count,double read_time);
77
static uint cache_record_length(JOIN *join,uint index);
78
static double prev_record_reads(JOIN *join, uint idx, table_map found_ref);
77
static uint32_t cache_record_length(JOIN *join,uint32_t index);
78
static double prev_record_reads(JOIN *join, uint32_t idx, table_map found_ref);
79
79
static bool get_best_combination(JOIN *join);
80
80
static store_key *get_store_key(THD *thd,
81
81
KEYUSE *keyuse, table_map used_tables,
82
82
KEY_PART_INFO *key_part, unsigned char *key_buff,
84
84
static bool make_simple_join(JOIN *join,Table *tmp_table);
85
85
static void make_outerjoin_info(JOIN *join);
86
86
static bool make_join_select(JOIN *join,SQL_SELECT *select,COND *item);
87
static bool make_join_readinfo(JOIN *join, uint64_t options, uint no_jbuf_after);
87
static bool make_join_readinfo(JOIN *join, uint64_t options, uint32_t no_jbuf_after);
88
88
static bool only_eq_ref_tables(JOIN *join, order_st *order, table_map tables);
89
89
static void update_depend_map(JOIN *join);
90
90
static void update_depend_map(JOIN *join, order_st *order);
175
175
static int remove_dup_with_compare(THD *thd, Table *entry, Field **field,
176
176
ulong offset,Item *having);
177
177
static int remove_dup_with_hash_index(THD *thd,Table *table,
178
uint field_count, Field **first_field,
178
uint32_t field_count, Field **first_field,
180
180
ulong key_length,Item *having);
181
static int join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count);
181
static int join_init_cache(THD *thd,JOIN_TAB *tables,uint32_t table_count);
182
182
static ulong used_blob_length(CACHE_FIELD **ptr);
183
183
static bool store_record_in_cache(JOIN_CACHE *cache);
184
184
static void reset_cache_read(JOIN_CACHE *cache);
198
198
static bool change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array,
199
199
List<Item> &new_list1,
200
200
List<Item> &new_list2,
201
uint elements, List<Item> &items);
201
uint32_t elements, List<Item> &items);
202
202
// Create list for using with tempory table
203
203
static bool change_refs_to_tmp_fields(THD *thd, Item **ref_pointer_array,
204
204
List<Item> &new_list1,
205
205
List<Item> &new_list2,
206
uint elements, List<Item> &items);
206
uint32_t elements, List<Item> &items);
207
207
static void init_tmptable_sum_functions(Item_sum **func);
208
208
static void update_tmptable_sum_func(Item_sum **func,Table *tmp_table);
209
209
static void copy_sum_funcs(Item_sum **func_ptr, Item_sum **end);
2604
2604
mysql_select(THD *thd, Item ***rref_pointer_array,
2605
TableList *tables, uint wild_num, List<Item> &fields,
2606
COND *conds, uint og_num, order_st *order, order_st *group,
2605
TableList *tables, uint32_t wild_num, List<Item> &fields,
2606
COND *conds, uint32_t og_num, order_st *order, order_st *group,
2607
2607
Item *having, order_st *proc_param, uint64_t select_options,
2608
2608
select_result *result, SELECT_LEX_UNIT *unit,
2609
2609
SELECT_LEX *select_lex)
4006
add_key_field(KEY_FIELD **key_fields,uint and_level, Item_func *cond,
4007
Field *field, bool eq_func, Item **value, uint num_values,
4006
add_key_field(KEY_FIELD **key_fields,uint32_t and_level, Item_func *cond,
4007
Field *field, bool eq_func, Item **value, uint32_t num_values,
4008
4008
table_map usable_tables, SARGABLE_PARAM **sargables)
4010
uint exists_optimize= 0;
4010
uint32_t exists_optimize= 0;
4011
4011
if (!(field->flags & PART_KEY_FLAG))
4013
4013
// Don't remove column IS NULL on a LEFT JOIN table
4178
add_key_equal_fields(KEY_FIELD **key_fields, uint and_level,
4178
add_key_equal_fields(KEY_FIELD **key_fields, uint32_t and_level,
4179
4179
Item_func *cond, Item_field *field_item,
4180
4180
bool eq_func, Item **val,
4181
uint num_values, table_map usable_tables,
4181
uint32_t num_values, table_map usable_tables,
4182
4182
SARGABLE_PARAM **sargables)
4184
4184
Field *field= field_item->field;
4567
4567
update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab,
4568
uint tables, COND *cond,
4568
uint32_t tables, COND *cond,
4569
4569
COND_EQUAL *cond_equal __attribute__((unused)),
4570
4570
table_map normal_tables, SELECT_LEX *select_lex,
4571
4571
SARGABLE_PARAM **sargables)
4573
4573
uint and_level,i,found_eq_constant;
4574
4574
KEY_FIELD *key_fields, *end, *field;
4576
uint m= cmax(select_lex->max_equal_elems,(uint32_t)1);
4576
uint32_t m= cmax(select_lex->max_equal_elems,(uint32_t)1);
4579
4579
We use the same piece of memory to store both KEY_FIELD