This is an automated email from the ASF dual-hosted git repository. yjhjstz pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 05c4df0076c87cc80c33852bac053f0dbecf48a2 Author: Soumyadeep Chakraborty <[email protected]> AuthorDate: Wed May 22 17:47:08 2024 -0700 analyze: Don't leak DatumHashTable We create and then destroy DatumHashTable in aggregate_leaf_partition_MCVs(), except for 1 path, where buildMCVArrayForStatsEntry() returns NULL. And since DatumHashTable is not allocated with HASH_CONTEXT, it is allocated under TopMemoryContext, as opposed to VacAttrStats->anl_context. The leak is obvious as shown below in a db with a 1000-part table: parts=# select name, level, sum(total_bytes) from gp_backend_memory_contexts where gp_segment_id = -1 and name = 'DatumHashTable' group by (name, level) order by 3 desc; name | level | sum ------+-------+----- (0 rows) parts=# analyze; ANALYZE -- Should be empty as ANALYZE is done but nope! -- With the patch, this returns empty. parts=# select name, level, sum(total_bytes) from gp_backend_memory_contexts where gp_segment_id = -1 and name = 'DatumHashTable' group by (name, level) order by 3 desc; name | level | sum ----------------+-------+------- DatumHashTable | 1 | 65536 (1 row) parts=# analyze; ANALYZE -- Keeps growing! parts=# select name, level, sum(total_bytes) from gp_backend_memory_contexts where gp_segment_id = -1 and name = 'DatumHashTable' group by (name, level) order by 3 desc; name | level | sum ----------------+-------+-------- DatumHashTable | 1 | 131072 (1 row) Reviewed-by: QingMa <[email protected]> Reviewed-by: Chris Hajas <[email protected]> Reviewed-by: Ashwin Agrawal <[email protected]> --- src/backend/commands/analyzeutils.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/commands/analyzeutils.c b/src/backend/commands/analyzeutils.c index f940a9ad12..83ef85a952 100644 --- a/src/backend/commands/analyzeutils.c +++ b/src/backend/commands/analyzeutils.c @@ -227,6 +227,7 @@ aggregate_leaf_partition_MCVs(Oid relationOid, ndistinct, sumReltuples); if (*result == NULL) { + hash_destroy(datumHash); *num_mcv = 0; return mcvpairArray; } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
