diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index b47db263ce9..8c129857095 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -91,7 +91,19 @@ TABLE_STATISTICS_CB::TABLE_STATISTICS_CB(): TABLE_STATISTICS_CB::~TABLE_STATISTICS_CB() { + Column_statistics *column_stats= table_stats->column_stats; + Column_statistics *column_stats_end= column_stats + table_stats->columns; DBUG_ASSERT(usage_count == 0); + + /* Free json histograms */ + for (; column_stats < column_stats_end ; column_stats++) + { + delete column_stats->histogram; + /* + Protect against possible other free in free_statistics_for_table() + */ + column_stats->histogram= 0; + } free_root(&mem_root, MYF(0)); } @@ -2381,6 +2393,7 @@ alloc_engine_independent_statistics(THD *thd, const TABLE_SHARE *table_share, bzero(idx_avg_frequency, sizeof(idx_avg_frequency) * key_parts); stats_cb->table_stats= table_stats; + table_stats->columns= table_share->fields; table_stats->column_stats= column_stats; table_stats->index_stats= index_stats; table_stats->idx_avg_frequency= idx_avg_frequency; diff --git a/sql/sql_statistics.h b/sql/sql_statistics.h index e8da71252e2..cf4fc4a4094 100644 --- a/sql/sql_statistics.h +++ b/sql/sql_statistics.h @@ -432,9 +432,9 @@ class Index_statistics; class Table_statistics { - public: my_bool cardinality_is_null; /* TRUE if the cardinality is unknown */ + uint columns; /* Number of columns in table */ ha_rows cardinality; /* Number of rows in the table */ uchar *min_max_record_buffers; /* Record buffers for min/max values */ Column_statistics *column_stats; /* Array of statistical data for columns */