From 7ebb64c557570647e3fcf6f5f1549e882ed26489 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Tue, 20 Jan 2026 13:13:47 +0900 Subject: [PATCH] Add routine to free MCVList This addition is in the same spirit as 32e27bd32082 for MVNDistinct and MVDependencies, except that we were missing a free routine for the third type of extended statistics, MCVList. I was not sure if we needed an equivalent for MCVList, but after more review of the main patch set for the import of extended statistics, it has become clear that we do. This is introduced as its own change as this routine can be useful on its own. This one is a piece that has not been written by Corey Huinker, I have just noticed it by myself on the way. Author: Michael Paquier Discussion: https://postgr.es/m/CADkLM=dpz3KFnqP-dgJ-zvRvtjsa8UZv8wDAQdqho=qN3kX0Zg@mail.gmail.com --- src/backend/statistics/mcv.c | 16 ++++++++++++++++ src/include/statistics/extended_stats_internal.h | 1 + 2 files changed, 17 insertions(+) diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c index e5ac422c1b4..de5a544b390 100644 --- a/src/backend/statistics/mcv.c +++ b/src/backend/statistics/mcv.c @@ -2171,3 +2171,19 @@ mcv_clause_selectivity_or(PlannerInfo *root, StatisticExtInfo *stat, return s; } + +/* + * Free allocations of a MCVList. + */ +void +statext_mcv_free(MCVList *mcvlist) +{ + for (int i = 0; i < mcvlist->nitems; i++) + { + MCVItem *item = &mcvlist->items[i]; + + pfree(item->values); + pfree(item->isnull); + } + pfree(mcvlist); +} diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index b5003ec242c..54b4a26273d 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -89,6 +89,7 @@ extern MCVList *statext_mcv_build(StatsBuildData *data, double totalrows, int stattarget); extern bytea *statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats); extern MCVList *statext_mcv_deserialize(bytea *data); +extern void statext_mcv_free(MCVList *mcvlist); extern MultiSortSupport multi_sort_init(int ndims); extern void multi_sort_add_dimension(MultiSortSupport mss, int sortdim,