summaryrefslogtreecommitdiff
path: root/sql/opt_range.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/opt_range.cc')
-rw-r--r--sql/opt_range.cc84
1 files changed, 54 insertions, 30 deletions
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 404c5a1f6d3..3180c509737 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -499,9 +499,9 @@ int SEL_IMERGE::or_sel_tree(RANGE_OPT_PARAM *param, SEL_TREE *tree)
if (trees_next == trees_end)
{
const int realloc_ratio= 2; /* Double size for next round */
- uint old_elements= (trees_end - trees);
- uint old_size= sizeof(SEL_TREE**) * old_elements;
- uint new_size= old_size * realloc_ratio;
+ size_t old_elements= (trees_end - trees);
+ size_t old_size= sizeof(SEL_TREE**) * old_elements;
+ size_t new_size= old_size * realloc_ratio;
SEL_TREE **new_trees;
if (!(new_trees= (SEL_TREE**)alloc_root(param->mem_root, new_size)))
return -1;
@@ -846,10 +846,10 @@ SEL_TREE::SEL_TREE(SEL_TREE *arg, bool without_merges,
SEL_IMERGE::SEL_IMERGE(SEL_IMERGE *arg, uint cnt,
RANGE_OPT_PARAM *param) : Sql_alloc()
{
- uint elements= (arg->trees_end - arg->trees);
+ size_t elements= (arg->trees_end - arg->trees);
if (elements > PREALLOCED_TREES)
{
- uint size= elements * sizeof (SEL_TREE **);
+ size_t size= elements * sizeof (SEL_TREE **);
if (!(trees= (SEL_TREE **)alloc_root(param->mem_root, size)))
goto mem_err;
}
@@ -951,7 +951,7 @@ int imerge_list_or_list(RANGE_OPT_PARAM *param,
uint rc;
bool is_last_check_pass= FALSE;
SEL_IMERGE *imerge= im1->head();
- uint elems= imerge->trees_next-imerge->trees;
+ uint elems= (uint)(imerge->trees_next-imerge->trees);
MEM_ROOT *mem_root= current_thd->mem_root;
im1->empty();
@@ -1051,7 +1051,7 @@ int imerge_list_or_tree(RANGE_OPT_PARAM *param,
SEL_TREE *or_tree= new (mem_root) SEL_TREE (tree, FALSE, param);
if (or_tree)
{
- uint elems= imerge->trees_next-imerge->trees;
+ uint elems= (uint)(imerge->trees_next-imerge->trees);
rc= imerge->or_sel_tree_with_checks(param, elems, or_tree,
TRUE, &is_last_check_pass);
if (!is_last_check_pass)
@@ -2897,7 +2897,7 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond)
uint keynr;
uint max_quick_key_parts= 0;
MY_BITMAP *used_fields= &table->cond_set;
- double table_records= table->stat_records();
+ double table_records= (double)table->stat_records();
DBUG_ENTER("calculate_cond_selectivity_for_table");
table->cond_selectivity= 1.0;
@@ -3994,8 +3994,8 @@ int find_used_partitions(PART_PRUNE_PARAM *ppar, SEL_ARG *key_tree)
store_length_array,
range_par->min_key,
range_par->max_key,
- tmp_min_key - range_par->min_key,
- tmp_max_key - range_par->max_key,
+ (uint)(tmp_min_key - range_par->min_key),
+ (uint)(tmp_max_key - range_par->max_key),
flag,
&ppar->part_iter);
if (!res)
@@ -4643,6 +4643,7 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge,
double roru_index_costs;
ha_rows roru_total_records;
double roru_intersect_part= 1.0;
+ size_t n_child_scans;
DBUG_ENTER("get_best_disjunct_quick");
DBUG_PRINT("info", ("Full table scan cost: %g", read_time));
@@ -4659,7 +4660,7 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge,
}
}
- uint n_child_scans= imerge->trees_next - imerge->trees;
+ n_child_scans= imerge->trees_next - imerge->trees;
if (!n_child_scans)
DBUG_RETURN(NULL);
@@ -4877,8 +4878,8 @@ skip_to_ror_scan:
(TIME_FOR_COMPARE_ROWID * M_LN2) +
get_sweep_read_cost(param, roru_total_records);
- DBUG_PRINT("info", ("ROR-union: cost %g, %d members", roru_total_cost,
- n_child_scans));
+ DBUG_PRINT("info", ("ROR-union: cost %g, %zu members",
+ roru_total_cost, n_child_scans));
TRP_ROR_UNION* roru;
if (roru_total_cost < read_time)
{
@@ -5203,7 +5204,7 @@ bool prepare_search_best_index_intersect(PARAM *param,
INDEX_SCAN_INFO **scan_ptr;
INDEX_SCAN_INFO *cpk_scan= NULL;
TABLE *table= param->table;
- uint n_index_scans= tree->index_scans_end - tree->index_scans;
+ uint n_index_scans= (uint)(tree->index_scans_end - tree->index_scans);
if (!n_index_scans)
return 1;
@@ -5846,7 +5847,7 @@ TRP_INDEX_INTERSECT *get_best_index_intersect(PARAM *param, SEL_TREE *tree,
}
}
- count= tree->index_scans_end - tree->index_scans;
+ count= (uint)(tree->index_scans_end - tree->index_scans);
for (i= 0; i < count; i++)
{
index_scan= tree->index_scans[i];
@@ -6506,7 +6507,7 @@ TRP_ROR_INTERSECT *get_best_ror_intersect(const PARAM *param, SEL_TREE *tree,
intersect_scans_best););
*are_all_covering= intersect->is_covering;
- uint best_num= intersect_scans_best - intersect_scans;
+ uint best_num= (uint)(intersect_scans_best - intersect_scans);
ror_intersect_cpy(intersect, intersect_best);
/*
@@ -6688,7 +6689,7 @@ TRP_ROR_INTERSECT *get_best_covering_ror_intersect(PARAM *param,
TRP_ROR_INTERSECT *trp;
if (!(trp= new (param->mem_root) TRP_ROR_INTERSECT))
DBUG_RETURN(trp);
- uint best_num= (ror_scan_mark - tree->ror_scans);
+ uint best_num= (uint)(ror_scan_mark - tree->ror_scans);
if (!(trp->first_scan= (ROR_SCAN_INFO**)alloc_root(param->mem_root,
sizeof(ROR_SCAN_INFO*)*
best_num)))
@@ -8557,6 +8558,34 @@ bool sel_trees_can_be_ored(RANGE_OPT_PARAM* param,
}
/*
+ Check whether the key parts inf_init..inf_end-1 of one index can compose
+ an infix for the key parts key_init..key_end-1 of another index
+*/
+
+static
+bool is_key_infix(KEY_PART *key_init, KEY_PART *key_end,
+ KEY_PART *inf_init, KEY_PART *inf_end)
+{
+ KEY_PART *key_part, *inf_part;
+ for (key_part= key_init; key_part < key_end; key_part++)
+ {
+ if (key_part->field->eq(inf_init->field))
+ break;
+ }
+ if (key_part == key_end)
+ return false;
+ for (key_part++, inf_part= inf_init + 1;
+ key_part < key_end && inf_part < inf_end;
+ key_part++, inf_part++)
+ {
+ if (!key_part->field->eq(inf_part->field))
+ return false;
+ }
+ return inf_part == inf_end;
+}
+
+
+/*
Check whether range parts of two trees must be ored for some indexes
SYNOPSIS
@@ -8612,14 +8641,9 @@ bool sel_trees_must_be_ored(RANGE_OPT_PARAM* param,
KEY_PART *key2_init= param->key[idx2]+tree2->keys[idx2]->part;
KEY_PART *key2_end= param->key[idx2]+tree2->keys[idx2]->max_part_no;
- KEY_PART *part1, *part2;
- for (part1= key1_init, part2= key2_init;
- part1 < key1_end && part2 < key2_end;
- part1++, part2++)
- {
- if (!part1->field->eq(part2->field))
- DBUG_RETURN(FALSE);
- }
+ if (!is_key_infix(key1_init, key1_end, key2_init, key2_end) &&
+ !is_key_infix(key2_init, key2_end, key1_init, key1_end))
+ DBUG_RETURN(FALSE);
}
}
@@ -11476,7 +11500,7 @@ int QUICK_RANGE_SELECT::get_next_prefix(uint prefix_length,
DBUG_RETURN(0);
}
- uint count= ranges.elements - (cur_range - (QUICK_RANGE**) ranges.buffer);
+ uint count= ranges.elements - (uint)(cur_range - (QUICK_RANGE**) ranges.buffer);
if (count == 0)
{
/* Ranges have already been used up before. None is left for read. */
@@ -11521,7 +11545,7 @@ int QUICK_RANGE_SELECT_GEOM::get_next()
DBUG_RETURN(result);
}
- uint count= ranges.elements - (cur_range - (QUICK_RANGE**) ranges.buffer);
+ uint count= ranges.elements - (uint)(cur_range - (QUICK_RANGE**) ranges.buffer);
if (count == 0)
{
/* Ranges have already been used up before. None is left for read. */
@@ -11975,7 +11999,7 @@ void QUICK_SELECT_I::add_key_and_length(String *key_names,
bool *first)
{
char buf[64];
- uint length;
+ size_t length;
KEY *key_info= head->key_info + index;
if (*first)
@@ -12529,7 +12553,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
{
cur_group_prefix_len+= cur_part->store_length;
++cur_group_key_parts;
- max_key_part= cur_part - cur_index_info->key_part + 1;
+ max_key_part= (uint)(cur_part - cur_index_info->key_part) + 1;
used_key_parts_map.set_bit(max_key_part);
}
else
@@ -13252,7 +13276,7 @@ get_field_keypart(KEY *index, Field *field)
part < end; part++)
{
if (field->eq(part->field))
- return part - index->key_part + 1;
+ return (uint)(part - index->key_part + 1);
}
return 0;
}