From 6685e1bbf2bf3dfc58bf4765e8d86216fb8a279a Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Wed, 27 Jan 2021 12:58:20 +0530 Subject: MDEV-24740: Selectivity for equi-join predicates not involed in ref access is not taken into account for join cardinality estimation 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. --- sql/sql_select.cc | 5 +---- sql/sql_statistics.cc | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'sql') 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 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(); -- cgit v1.2.1