Commit a49ebf71 authored by Monty's avatar Monty

Fixed memory leak when using histograms

This was introduced in last merge with 10.6
The reason is that 10.6 does not need anything special to free histograms
as everything is allocated on a memroot.
In 10.10 histograms is using the vector class, which has some problems:
- No automatic free
- No memory usage accounting
(we should at some point remove vector usage because of the above problem)

Fixed by expliciting freeing histograms when freeing TABLE_STATISTICS
objects.
parent 0563106b
......@@ -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;
......
......@@ -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 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment