Skip to content

Commit a49ebf7

Browse files
committed
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.
1 parent 0563106 commit a49ebf7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

sql/sql_statistics.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,19 @@ TABLE_STATISTICS_CB::TABLE_STATISTICS_CB():
9191

9292
TABLE_STATISTICS_CB::~TABLE_STATISTICS_CB()
9393
{
94+
Column_statistics *column_stats= table_stats->column_stats;
95+
Column_statistics *column_stats_end= column_stats + table_stats->columns;
9496
DBUG_ASSERT(usage_count == 0);
97+
98+
/* Free json histograms */
99+
for (; column_stats < column_stats_end ; column_stats++)
100+
{
101+
delete column_stats->histogram;
102+
/*
103+
Protect against possible other free in free_statistics_for_table()
104+
*/
105+
column_stats->histogram= 0;
106+
}
95107
free_root(&mem_root, MYF(0));
96108
}
97109

@@ -2381,6 +2393,7 @@ alloc_engine_independent_statistics(THD *thd, const TABLE_SHARE *table_share,
23812393
bzero(idx_avg_frequency, sizeof(idx_avg_frequency) * key_parts);
23822394

23832395
stats_cb->table_stats= table_stats;
2396+
table_stats->columns= table_share->fields;
23842397
table_stats->column_stats= column_stats;
23852398
table_stats->index_stats= index_stats;
23862399
table_stats->idx_avg_frequency= idx_avg_frequency;

sql/sql_statistics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,9 @@ class Index_statistics;
432432

433433
class Table_statistics
434434
{
435-
436435
public:
437436
my_bool cardinality_is_null; /* TRUE if the cardinality is unknown */
437+
uint columns; /* Number of columns in table */
438438
ha_rows cardinality; /* Number of rows in the table */
439439
uchar *min_max_record_buffers; /* Record buffers for min/max values */
440440
Column_statistics *column_stats; /* Array of statistical data for columns */

0 commit comments

Comments
 (0)