Commit 9020baf1 authored by Sergei Petrunia's avatar Sergei Petrunia

Trivial fix: Make test_if_cheaper_ordering() use actual_rec_per_key()

Discovered this while working on MDEV-34720: test_if_cheaper_ordering()
uses rec_per_key, while the original estimate for the access method
is produced in best_access_path() by using actual_rec_per_key().

Make test_if_cheaper_ordering() also use actual_rec_per_key().
Also make several getter function "const" to make this compile.
Also adjusted the testcase to handle this (the change backported from
11.0)
parent 9db2b327
...@@ -554,6 +554,7 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -554,6 +554,7 @@ id select_type table type possible_keys key key_len ref rows Extra
# #
# MDEV-6081: ORDER BY+ref(const): selectivity is very incorrect (MySQL Bug#14338686) # MDEV-6081: ORDER BY+ref(const): selectivity is very incorrect (MySQL Bug#14338686)
# #
insert into t2 select seq,seq,seq from seq_10000_to_11000;
alter table t2 add key2 int; alter table t2 add key2 int;
update t2 set key2=key1; update t2 set key2=key1;
alter table t2 add key(key2); alter table t2 add key(key2);
......
...@@ -558,7 +558,9 @@ from ...@@ -558,7 +558,9 @@ from
--echo # --echo #
--echo # MDEV-6081: ORDER BY+ref(const): selectivity is very incorrect (MySQL Bug#14338686) --echo # MDEV-6081: ORDER BY+ref(const): selectivity is very incorrect (MySQL Bug#14338686)
--echo # --echo #
--source include/have_sequence.inc
insert into t2 select seq,seq,seq from seq_10000_to_11000;
alter table t2 add key2 int; alter table t2 add key2 int;
update t2 set key2=key1; update t2 set key2=key1;
alter table t2 add key(key2); alter table t2 add key(key2);
......
...@@ -30391,7 +30391,8 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table, ...@@ -30391,7 +30391,8 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
else else
{ {
const KEY *ref_keyinfo= table->key_info + ref_key; const KEY *ref_keyinfo= table->key_info + ref_key;
refkey_rows_estimate= ref_keyinfo->rec_per_key[tab->ref.key_parts - 1]; refkey_rows_estimate=
(ha_rows)ref_keyinfo->actual_rec_per_key(tab->ref.key_parts - 1);
} }
set_if_bigger(refkey_rows_estimate, 1); set_if_bigger(refkey_rows_estimate, 1);
} }
...@@ -472,7 +472,7 @@ class Index_statistics ...@@ -472,7 +472,7 @@ class Index_statistics
bool avg_frequency_is_inited() { return avg_frequency != NULL; } bool avg_frequency_is_inited() { return avg_frequency != NULL; }
double get_avg_frequency(uint i) double get_avg_frequency(uint i) const
{ {
return (double) avg_frequency[i] / Scale_factor_avg_frequency; return (double) avg_frequency[i] / Scale_factor_avg_frequency;
} }
......
...@@ -166,7 +166,7 @@ typedef struct st_key { ...@@ -166,7 +166,7 @@ typedef struct st_key {
engine_option_value *option_list; engine_option_value *option_list;
ha_index_option_struct *option_struct; /* structure with parsed options */ ha_index_option_struct *option_struct; /* structure with parsed options */
double actual_rec_per_key(uint i); double actual_rec_per_key(uint i) const;
bool without_overlaps; bool without_overlaps;
/* /*
......
...@@ -10034,7 +10034,7 @@ uint TABLE_SHARE::actual_n_key_parts(THD *thd) ...@@ -10034,7 +10034,7 @@ uint TABLE_SHARE::actual_n_key_parts(THD *thd)
} }
double KEY::actual_rec_per_key(uint i) double KEY::actual_rec_per_key(uint i) const
{ {
if (rec_per_key == 0) if (rec_per_key == 0)
return 0; return 0;
......
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