Add routine to free MCVList
authorMichael Paquier <michael@paquier.xyz>
Tue, 20 Jan 2026 04:13:47 +0000 (13:13 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 20 Jan 2026 04:13:47 +0000 (13:13 +0900)
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 <michael@paquier.xyz>
Discussion: https://postgr.es/m/CADkLM=dpz3KFnqP-dgJ-zvRvtjsa8UZv8wDAQdqho=qN3kX0Zg@mail.gmail.com

src/backend/statistics/mcv.c
src/include/statistics/extended_stats_internal.h

index e5ac422c1b4e49ff6357ba9da10a0aa14e2dae06..de5a544b390fde77f7674880a776994bff9aec1e 100644 (file)
@@ -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);
+}
index b5003ec242c15b1a52c3b3c1bceb7bfeda870bcb..54b4a26273d805eff364bb4e1e982b321f280321 100644 (file)
@@ -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,