diff options
author | Varun Gupta <varun.gupta@mariadb.com> | 2021-01-27 12:58:20 +0530 |
---|---|---|
committer | Varun Gupta <varun.gupta@mariadb.com> | 2021-01-31 19:00:35 +0530 |
commit | 6685e1bbf2bf3dfc58bf4765e8d86216fb8a279a (patch) | |
tree | 56fa568e0350e7658a29544882c78613a425334e /sql | |
parent | 95a2bca01f423dc97281709a7871f5901fd05c70 (diff) | |
download | mariadb-git-bb-10.6-mdev24740.tar.gz |
MDEV-24740: Selectivity for equi-join predicates not involed in ref access is not taken into account for join cardinality estimationbb-10.6-mdev24740
First the function was checking if there is a keyuse only then we were
trying to use the function to get estimates for the equi-join predicated.
This function can calculate the estimates for selectivity for an non-indexed
equi-join condition also.
Second change is done when we try to get the avg frequency of a column,
then we need to make sure that statistics are available in the statistical
tables. This check was missing and so get_column_avg_frequency() was
returning zero for columns.
Updated few tests results.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_select.cc | 5 | ||||
-rw-r--r-- | sql/sql_statistics.cc | 2 |
2 files changed, 2 insertions, 5 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index c8c238945ae..ca867b04f51 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -9033,9 +9033,6 @@ double table_multi_eq_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, if (!cond_equal || !cond_equal->current_level.elements) return sel; - if (!s->keyuse) - return sel; - Item_equal *item_equal; List_iterator_fast<Item_equal> it(cond_equal->current_level); TABLE *table= s->table; @@ -9126,7 +9123,7 @@ double table_multi_eq_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s, curr_eq_fld_sel= get_column_avg_frequency(fld) / fld->table->stat_records(); if (curr_eq_fld_sel < 1.0) - set_if_bigger(eq_fld_sel, curr_eq_fld_sel); + set_if_smaller(eq_fld_sel, curr_eq_fld_sel); } sel*= eq_fld_sel; } diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index 7b600bd45c4..5c6c2499485 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -3700,7 +3700,7 @@ double get_column_avg_frequency(Field * field) Column_statistics *col_stats= field->read_stats; - if (!col_stats) + if (!is_eits_usable(field)) res= (double)table->stat_records(); else res= col_stats->get_avg_frequency(); |