summaryrefslogtreecommitdiff
path: root/sql/sql_statistics.cc
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2021-02-09 20:27:21 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2021-02-16 11:53:13 +0530
commita461e4d306bc53134cefa0eeeb624f3d9eba70f8 (patch)
tree504a450a0f576e4a3a7d291b37ca7c3253f71482 /sql/sql_statistics.cc
parente926964cb8c2ddad2304adc3ff5739a3bb91aea3 (diff)
downloadmariadb-git-a461e4d306bc53134cefa0eeeb624f3d9eba70f8.tar.gz
MDEV-19474: Histogram statistics are used even with optimizer_use_condition_selectivity=3
The issue here was histogram statistics were being used even when the level of optimizer_use_condition_selectivity doesn't allow usage of statistics from histogram. The histogram statistics are read for a table only when optimizer_use_condition_selectivity > 3. But the TABLE structure can be stored in the internal table cache and be reused for the next query. So in this case the histogram statistics will be available for the next query. The fix would be to make sure to use the histogram statistics only when optimizer_use_condition_selectivity > 3.
Diffstat (limited to 'sql/sql_statistics.cc')
-rw-r--r--sql/sql_statistics.cc9
1 files changed, 5 insertions, 4 deletions
diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc
index 39fcfd7e6db..f2aa8b8063e 100644
--- a/sql/sql_statistics.cc
+++ b/sql/sql_statistics.cc
@@ -3732,6 +3732,7 @@ double get_column_range_cardinality(Field *field,
if (!table->stats_is_read)
return tab_records;
+ THD *thd= table->in_use;
double col_nulls= tab_records * col_stats->get_nulls_ratio();
double col_non_nulls= tab_records - col_nulls;
@@ -3762,7 +3763,7 @@ double get_column_range_cardinality(Field *field,
col_stats->min_max_values_are_provided())
{
Histogram *hist= &col_stats->histogram;
- if (hist->is_available())
+ if (hist->is_usable(thd))
{
store_key_image_to_rec(field, (uchar *) min_endp->key,
field->key_length());
@@ -3806,10 +3807,10 @@ double get_column_range_cardinality(Field *field,
max_mp_pos= 1.0;
Histogram *hist= &col_stats->histogram;
- if (!hist->is_available())
- sel= (max_mp_pos - min_mp_pos);
- else
+ if (hist->is_usable(thd))
sel= hist->range_selectivity(min_mp_pos, max_mp_pos);
+ else
+ sel= (max_mp_pos - min_mp_pos);
res= col_non_nulls * sel;
set_if_bigger(res, col_stats->get_avg_frequency());
}