70
70
extern std::bitset<12> test_flags;
72
72
/** Declarations of static functions used in this source file. */
73
static bool make_group_fields(JOIN *main_join, JOIN *curr_join);
74
static void calc_group_buffer(JOIN *join,order_st *group);
75
static bool alloc_group_fields(JOIN *join,order_st *group);
76
static uint32_t cache_record_length(JOIN *join, uint32_t index);
77
static double prev_record_reads(JOIN *join, uint32_t idx, table_map found_ref);
78
static bool get_best_combination(JOIN *join);
79
static void set_position(JOIN *join,
73
static bool make_group_fields(Join *main_join, Join *curr_join);
74
static void calc_group_buffer(Join *join,order_st *group);
75
static bool alloc_group_fields(Join *join,order_st *group);
76
static uint32_t cache_record_length(Join *join, uint32_t index);
77
static double prev_record_reads(Join *join, uint32_t idx, table_map found_ref);
78
static bool get_best_combination(Join *join);
79
static void set_position(Join *join,
82
82
optimizer::KeyUse *key);
83
static bool choose_plan(JOIN *join,table_map join_tables);
84
static void best_access_path(JOIN *join, JoinTable *s,
83
static bool choose_plan(Join *join,table_map join_tables);
84
static void best_access_path(Join *join, JoinTable *s,
86
86
table_map remaining_tables,
88
88
double record_count,
90
static void optimize_straight_join(JOIN *join, table_map join_tables);
91
static bool greedy_search(JOIN *join, table_map remaining_tables, uint32_t depth, uint32_t prune_level);
92
static bool best_extension_by_limited_search(JOIN *join,
90
static void optimize_straight_join(Join *join, table_map join_tables);
91
static bool greedy_search(Join *join, table_map remaining_tables, uint32_t depth, uint32_t prune_level);
92
static bool best_extension_by_limited_search(Join *join,
93
93
table_map remaining_tables,
95
95
double record_count,
98
98
uint32_t prune_level);
99
static uint32_t determine_search_depth(JOIN* join);
100
static bool make_simple_join(JOIN *join,Table *tmp_table);
101
static void make_outerjoin_info(JOIN *join);
102
static bool make_join_select(JOIN *join, optimizer::SqlSelect *select,COND *item);
103
static bool make_join_readinfo(JOIN *join);
104
static void update_depend_map(JOIN *join);
105
static void update_depend_map(JOIN *join, order_st *order);
106
static order_st *remove_constants(JOIN *join,order_st *first_order,COND *cond, bool change_list, bool *simple_order);
107
static int return_zero_rows(JOIN *join,
99
static uint32_t determine_search_depth(Join* join);
100
static bool make_simple_join(Join *join,Table *tmp_table);
101
static void make_outerjoin_info(Join *join);
102
static bool make_join_select(Join *join, optimizer::SqlSelect *select,COND *item);
103
static bool make_join_readinfo(Join *join);
104
static void update_depend_map(Join *join);
105
static void update_depend_map(Join *join, order_st *order);
106
static order_st *remove_constants(Join *join,order_st *first_order,COND *cond, bool change_list, bool *simple_order);
107
static int return_zero_rows(Join *join,
108
108
select_result *res,
109
109
TableList *tables,
110
110
List<Item> &fields,
112
112
uint64_t select_options,
113
113
const char *info,
115
static COND *simplify_joins(JOIN *join, List<TableList> *join_list, COND *conds, bool top);
116
static int remove_duplicates(JOIN *join,Table *entry,List<Item> &fields, Item *having);
115
static COND *simplify_joins(Join *join, List<TableList> *join_list, COND *conds, bool top);
116
static int remove_duplicates(Join *join,Table *entry,List<Item> &fields, Item *having);
117
117
static int setup_without_group(Session *session,
118
118
Item **ref_pointer_array,
119
119
TableList *tables,
1791
1791
is called after all rows are sent, but before EOF packet is sent.
1793
1793
For a simple SELECT with no subqueries this function performs a full
1794
cleanup of the JOIN and calls mysql_unlock_read_tables to free used base
1794
cleanup of the Join and calls mysql_unlock_read_tables to free used base
1797
If a JOIN is executed for a subquery or if it has a subquery, we can't
1797
If a Join is executed for a subquery or if it has a subquery, we can't
1798
1798
do the full cleanup and need to do a partial cleanup only.
1799
- If a JOIN is not the top level join, we must not unlock the tables
1799
- If a Join is not the top level join, we must not unlock the tables
1800
1800
because the outer select may not have been evaluated yet, and we
1801
1801
can't unlock only selected tables of a query.
1802
- Additionally, if this JOIN corresponds to a correlated subquery, we
1802
- Additionally, if this Join corresponds to a correlated subquery, we
1803
1803
should not free quick selects and join buffers because they will be
1804
1804
needed for the next execution of the correlated subquery.
1805
- However, if this is a JOIN for a [sub]select, which is not
1805
- However, if this is a Join for a [sub]select, which is not
1806
1806
a correlated subquery itself, but has subqueries, we can free it
1807
fully and also free JOINs of all its subqueries. The exception
1807
fully and also free Joins of all its subqueries. The exception
1808
1808
is a subquery in SELECT list, e.g: @n
1809
1809
SELECT a, (select cmax(b) from t1) group by c @n
1810
1810
This subquery will not be evaluated at first sweep and its value will