From a9c09c95bdd33ee0cbd3fb3254753ab2fc56f2a5 Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Tue, 28 Aug 2018 21:59:11 +0530 Subject: MDEV-15306: Wrong/Unexpected result with the value optimizer_use_condition_selectivity set to 4 Currently for selectivity calculation we perform range analysis for a column even when we don't have any statistics(EITS). This makes less sense but is used to catch contradiction for WHERE condition. So the solution is to not perform range analysis for selectivity calculation for columns that do not have statistics. --- sql/sql_statistics.h | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'sql/sql_statistics.h') diff --git a/sql/sql_statistics.h b/sql/sql_statistics.h index 6a43e42ab96..f28d56e4a69 100644 --- a/sql/sql_statistics.h +++ b/sql/sql_statistics.h @@ -342,12 +342,17 @@ private: public: Histogram histogram; + + uint32 no_values_provided_bitmap() + { + return + ((1 << (COLUMN_STAT_HISTOGRAM-COLUMN_STAT_COLUMN_NAME))-1) << + (COLUMN_STAT_COLUMN_NAME+1); + } void set_all_nulls() { - column_stat_nulls= - ((1 << (COLUMN_STAT_HISTOGRAM-COLUMN_STAT_COLUMN_NAME))-1) << - (COLUMN_STAT_COLUMN_NAME+1); + column_stat_nulls= no_values_provided_bitmap(); } void set_not_null(uint stat_field_no) @@ -393,8 +398,22 @@ public: bool min_max_values_are_provided() { return !is_null(COLUMN_STAT_MIN_VALUE) && - !is_null(COLUMN_STAT_MIN_VALUE); - } + !is_null(COLUMN_STAT_MAX_VALUE); + } + /* + This function checks whether the values for the fields of the statistical + tables that were NULL by DEFAULT for a column have changed or not. + + @retval + TRUE: Statistics are not present for a column + FALSE: Statisitics are present for a column + */ + bool no_stat_values_provided() + { + if (column_stat_nulls == no_values_provided_bitmap()) + return true; + return false; + } }; -- cgit v1.2.1