summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc37
1 files changed, 22 insertions, 15 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 3dae58a78e2..641a398cbc6 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -107,10 +107,6 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, KEYUSE *org_keyuse,
static ha_rows get_quick_record_count(THD *thd, SQL_SELECT *select,
TABLE *table,
const key_map *keys,ha_rows limit);
-void best_access_path(JOIN *join, JOIN_TAB *s,
- table_map remaining_tables, uint idx,
- bool disable_jbuf, double record_count,
- POSITION *pos, POSITION *loose_scan_pos);
static void optimize_straight_join(JOIN *join, table_map join_tables);
static bool greedy_search(JOIN *join, table_map remaining_tables,
uint depth, uint prune_level,
@@ -5479,6 +5475,13 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
{
if (choose_plan(join, all_table_map & ~join->const_table_map))
goto error;
+
+#ifdef HAVE_valgrind
+ // JOIN::positions holds the current query plan. We've already
+ // made the plan choice, so we should only use JOIN::best_positions
+ for (uint k=join->const_tables; k < join->table_count; k++)
+ MEM_UNDEFINED(&join->positions[k], sizeof(join->positions[k]));
+#endif
}
else
{
@@ -7178,6 +7181,7 @@ void
best_access_path(JOIN *join,
JOIN_TAB *s,
table_map remaining_tables,
+ const POSITION *join_positions,
uint idx,
bool disable_jbuf,
double record_count,
@@ -7298,7 +7302,7 @@ best_access_path(JOIN *join,
if (!keyuse->val->maybe_null || keyuse->null_rejecting)
notnull_part|=keyuse->keypart_map;
- double tmp2= prev_record_reads(join->positions, idx,
+ double tmp2= prev_record_reads(join_positions, idx,
(found_ref | keyuse->used_tables));
if (tmp2 < best_prev_record_reads)
{
@@ -7340,7 +7344,7 @@ best_access_path(JOIN *join,
Really, there should be records=0.0 (yes!)
but 1.0 would be probably safer
*/
- tmp= prev_record_reads(join->positions, idx, found_ref);
+ tmp= prev_record_reads(join_positions, idx, found_ref);
records= 1.0;
type= JT_FT;
trace_access_idx.add("access_type", join_type_str[type])
@@ -7369,7 +7373,7 @@ best_access_path(JOIN *join,
type= JT_EQ_REF;
trace_access_idx.add("access_type", join_type_str[type])
.add("index", keyinfo->name);
- tmp = prev_record_reads(join->positions, idx, found_ref);
+ tmp = prev_record_reads(join_positions, idx, found_ref);
records=1.0;
}
else
@@ -7657,7 +7661,8 @@ best_access_path(JOIN *join,
}
tmp= COST_ADD(tmp, s->startup_cost);
- loose_scan_opt.check_ref_access_part2(key, start_key, records, tmp);
+ loose_scan_opt.check_ref_access_part2(key, start_key, records, tmp,
+ found_ref);
} /* not ft_key */
if (records < DBL_MAX)
@@ -8447,7 +8452,8 @@ optimize_straight_join(JOIN *join, table_map join_tables)
trace_one_table.add_table_name(s);
}
/* Find the best access method from 's' to the current partial plan */
- best_access_path(join, s, join_tables, idx, disable_jbuf, record_count,
+ best_access_path(join, s, join_tables, join->positions, idx,
+ disable_jbuf, record_count,
position, &loose_scan_pos);
/* compute the cost of the new plan extended with 's' */
@@ -9376,8 +9382,8 @@ best_extension_by_limited_search(JOIN *join,
/* Find the best access method from 's' to the current partial plan */
POSITION loose_scan_pos;
- best_access_path(join, s, remaining_tables, idx, disable_jbuf,
- record_count, position, &loose_scan_pos);
+ best_access_path(join, s, remaining_tables, join->positions, idx,
+ disable_jbuf, record_count, position, &loose_scan_pos);
/* Compute the cost of extending the plan with 's' */
current_record_count= COST_MULT(record_count, position->records_read);
@@ -9781,11 +9787,11 @@ cache_record_length(JOIN *join,uint idx)
*/
double
-prev_record_reads(POSITION *positions, uint idx, table_map found_ref)
+prev_record_reads(const POSITION *positions, uint idx, table_map found_ref)
{
double found=1.0;
- POSITION *pos_end= positions - 1;
- for (POSITION *pos= positions + idx - 1; pos != pos_end; pos--)
+ const POSITION *pos_end= positions - 1;
+ for (const POSITION *pos= positions + idx - 1; pos != pos_end; pos--)
{
if (pos->table->table->map & found_ref)
{
@@ -16675,7 +16681,8 @@ void optimize_wo_join_buffering(JOIN *join, uint first_tab, uint last_tab,
if ((i == first_tab && first_alt) || join->positions[i].use_join_buffer)
{
/* Find the best access method that would not use join buffering */
- best_access_path(join, rs, reopt_remaining_tables, i,
+ best_access_path(join, rs, reopt_remaining_tables,
+ join->positions, i,
TRUE, rec_count,
&pos, &loose_scan_pos);
}