Release memory allocated by ndistinct_for_combination() Building extended statistics of type "ndistinct" calls ndistinct_for_combination() once for every combination of columns. Each call allocates arrays for the whole sample and never frees them, with memory accumulating until the whole statistics object is built. The sample has 300 multiplied by target rows. With large statistics targets (default_statistics_target up to 10k), this can add up to gigabytes worth of memory, useless once a combination is computed.
ndistinct_for_combination() is now called in a dedicated memory context, reset after each combination is computed. We only need the estimated number of distinct values, so there is no need to copy anything out of the memory context. Similar fixes have been done in 83772cc78e03 and ad8a166ca868 for other areas of the extended stats computations. Author: Ilia Evdokimov <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 14 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/a8c98c8843678560364eb20fe203046b183ccf6d Modified Files -------------- src/backend/statistics/mvdistinct.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
