1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-10 04:22:00 +03:00

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.
This commit is contained in:
Monty
2023-10-16 17:14:24 +03:00
parent 0563106b1a
commit a49ebf71af
2 changed files with 14 additions and 1 deletions

View File

@ -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;

View File

@ -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 */