Commit 41348a43 authored by Monty's avatar Monty Committed by Sergei Golubchik

Change class variable names in rowid_filter to longer, more clear names

No code logic changes was done

a     -> gain
b     -> cost_of_building_range_filter
a_adj -> gain_adj
r     -> row_combinations

Other things:
- Optimized the layout of class Range_rowid_filter_cost_info.
  One effect was that I moved key_no to the private section to get
  better alignment and had to introduce a get_key_no() function.
- Indentation changes in rowid_filter.cc to avoid long rows.
parent a543b2c0
......@@ -692,7 +692,7 @@ void print_best_access_for_table(THD *thd, POSITION *pos,
obj.add("uses_join_buffering", pos->use_join_buffer);
if (pos->range_rowid_filter_info)
{
uint key_no= pos->range_rowid_filter_info->key_no;
uint key_no= pos->range_rowid_filter_info->get_key_no();
obj.add("rowid_filter_key",
pos->table->table->key_info[key_no].name);
}
......
......@@ -24,8 +24,8 @@
inline
double Range_rowid_filter_cost_info::lookup_cost(
Rowid_filter_container_type cont_type)
double Range_rowid_filter_cost_info::
lookup_cost(Rowid_filter_container_type cont_type)
{
switch (cont_type) {
case SORTED_ARRAY_CONTAINER:
......@@ -44,8 +44,8 @@ double Range_rowid_filter_cost_info::lookup_cost(
*/
inline
double Range_rowid_filter_cost_info::avg_access_and_eval_gain_per_row(
Rowid_filter_container_type cont_type)
double Range_rowid_filter_cost_info::
avg_access_and_eval_gain_per_row(Rowid_filter_container_type cont_type)
{
return (1+1.0/TIME_FOR_COMPARE) * (1 - selectivity) -
lookup_cost(cont_type);
......@@ -76,10 +76,11 @@ double Range_rowid_filter_cost_info::avg_access_and_eval_gain_per_row(
*/
inline
double Range_rowid_filter_cost_info::avg_adjusted_gain_per_row(
double access_cost_factor)
double Range_rowid_filter_cost_info::
avg_adjusted_gain_per_row(double access_cost_factor)
{
return a - (1 - access_cost_factor) * (1 - selectivity);
DBUG_ASSERT(access_cost_factor >= 0.0 && access_cost_factor <= 1.0);
return gain - (1 - access_cost_factor) * (1 - selectivity);
}
......@@ -93,10 +94,11 @@ double Range_rowid_filter_cost_info::avg_adjusted_gain_per_row(
*/
inline void
Range_rowid_filter_cost_info::set_adjusted_gain_param(double access_cost_factor)
Range_rowid_filter_cost_info::
set_adjusted_gain_param(double access_cost_factor)
{
a_adj= avg_adjusted_gain_per_row(access_cost_factor);
cross_x_adj= b / a_adj;
gain_adj= avg_adjusted_gain_per_row(access_cost_factor);
cross_x_adj= cost_of_building_range_filter / gain_adj;
}
......@@ -118,13 +120,13 @@ void Range_rowid_filter_cost_info::init(Rowid_filter_container_type cont_type,
table= tab;
key_no= idx;
est_elements= (ulonglong) table->opt_range[key_no].rows;
b= build_cost(container_type);
cost_of_building_range_filter= build_cost(container_type);
selectivity= est_elements/((double) table->stat_records());
a= avg_access_and_eval_gain_per_row(container_type);
if (a > 0)
cross_x= b/a;
gain= avg_access_and_eval_gain_per_row(container_type);
if (gain > 0)
cross_x= cost_of_building_range_filter/gain;
else
cross_x= b+1;
cross_x= cost_of_building_range_filter+1;
abs_independent.clear_all();
}
......@@ -179,7 +181,7 @@ int compare_range_rowid_filter_cost_info_by_a(
Range_rowid_filter_cost_info **filter_ptr_1,
Range_rowid_filter_cost_info **filter_ptr_2)
{
double diff= (*filter_ptr_2)->get_a() - (*filter_ptr_1)->get_a();
double diff= (*filter_ptr_2)->get_gain() - (*filter_ptr_1)->get_gain();
return (diff < 0 ? -1 : (diff > 0 ? 1 : 0));
}
......@@ -206,7 +208,8 @@ void TABLE::prune_range_rowid_filters()
the elements if this bit matrix.
*/
Range_rowid_filter_cost_info **filter_ptr_1= range_rowid_filter_cost_info_ptr;
Range_rowid_filter_cost_info **filter_ptr_1=
range_rowid_filter_cost_info_ptr;
for (uint i= 0;
i < range_rowid_filter_cost_info_elems;
i++, filter_ptr_1++)
......@@ -245,7 +248,7 @@ void TABLE::prune_range_rowid_filters()
*/
Range_rowid_filter_cost_info **cand_filter_ptr=
range_rowid_filter_cost_info_ptr;
range_rowid_filter_cost_info_ptr;
for (uint i= 0;
i < range_rowid_filter_cost_info_elems;
i++, cand_filter_ptr++)
......@@ -439,7 +442,7 @@ void Range_rowid_filter_cost_info::trace_info(THD *thd)
{
Json_writer_object js_obj(thd);
js_obj.add("key", table->key_info[key_no].name);
js_obj.add("build_cost", b);
js_obj.add("build_cost", cost_of_building_range_filter);
js_obj.add("rows", est_elements);
}
......
......@@ -396,14 +396,16 @@ class Range_rowid_filter_cost_info : public Sql_alloc
TABLE *table;
/* Estimated number of elements in the filter */
ulonglong est_elements;
/* The cost of building the range filter */
double b;
/* The index whose range scan would be used to build the range filter */
uint key_no;
double cost_of_building_range_filter;
/*
a*N-b yields the gain of the filter
for N key tuples of the index key_no
(gain*row_combinations)-cost_of_building_range_filter yields the gain of
the filter for 'row_combinations' key tuples of the index key_no
calculated with avg_access_and_eval_gain_per_row(container_type);
*/
double a;
/* The value of N where the gain is 0 */
double gain;
/* The value of row_combinations where the gain is 0 */
double cross_x;
/* Used for pruning of the potential range filters */
key_map abs_independent;
......@@ -412,16 +414,14 @@ class Range_rowid_filter_cost_info : public Sql_alloc
These two parameters are used to choose the best range filter
in the function TABLE::best_range_rowid_filter_for_partial_join
*/
double a_adj;
double gain_adj;
double cross_x_adj;
public:
/* The type of the container of the range filter */
Rowid_filter_container_type container_type;
/* The index whose range scan would be used to build the range filter */
uint key_no;
/* The selectivity of the range filter */
double selectivity;
/* The type of the container of the range filter */
Rowid_filter_container_type container_type;
Range_rowid_filter_cost_info() : table(0), key_no(0) {}
......@@ -440,29 +440,30 @@ class Range_rowid_filter_cost_info : public Sql_alloc
inline void set_adjusted_gain_param(double access_cost_factor);
/* Get the gain that usage of filter promises for r key tuples */
inline double get_gain(double r)
inline double get_gain(double row_combinations)
{
return r * a - b;
return row_combinations * gain - cost_of_building_range_filter;
}
/* Get the adjusted gain that usage of filter promises for r key tuples */
inline double get_adjusted_gain(double r)
inline double get_adjusted_gain(double row_combinations)
{
return r * a_adj - b;
return row_combinations * gain_adj - cost_of_building_range_filter;
}
/*
The gain promised by usage of the filter for r key tuples
due to less condition evaluations
*/
inline double get_cmp_gain(double r)
inline double get_cmp_gain(double row_combinations)
{
return r * (1 - selectivity) / TIME_FOR_COMPARE;
return row_combinations * (1 - selectivity) / TIME_FOR_COMPARE;
}
Rowid_filter_container *create_container();
double get_a() { return a; }
double get_gain() { return gain; }
uint get_key_no() { return key_no; }
void trace_info(THD *thd);
......
......@@ -1917,9 +1917,9 @@ bool JOIN::make_range_rowid_filters()
continue;
DBUG_ASSERT(!(tab->ref.key >= 0 &&
tab->ref.key == (int) tab->range_rowid_filter_info->key_no));
tab->ref.key == (int) tab->range_rowid_filter_info->get_key_no()));
DBUG_ASSERT(!(tab->ref.key == -1 && tab->quick &&
tab->quick->index == tab->range_rowid_filter_info->key_no));
tab->quick->index == tab->range_rowid_filter_info->get_key_no()));
int err;
SQL_SELECT *sel= NULL;
......@@ -1932,7 +1932,7 @@ bool JOIN::make_range_rowid_filters()
key_map filter_map;
filter_map.clear_all();
filter_map.set_bit(tab->range_rowid_filter_info->key_no);
filter_map.set_bit(tab->range_rowid_filter_info->get_key_no());
filter_map.merge(tab->table->with_impossible_ranges);
bool force_index_save= tab->table->force_index;
tab->table->force_index= true;
......@@ -8401,7 +8401,7 @@ best_access_path(JOIN *join,
tmp-= filter->get_adjusted_gain(rows) - filter->get_cmp_gain(rows);
DBUG_ASSERT(tmp >= 0);
trace_access_idx.add("rowid_filter_key",
table->key_info[filter->key_no].name);
table->key_info[filter->get_key_no()].name);
}
}
trace_access_idx.add("rows", records).add("cost", tmp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment