pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Release memory allocated by ndistinct_for_combination() 7+ messages / 1 participants [nested] [flat]
* pgsql: Release memory allocated by ndistinct_for_combination() @ 2026-10-14 01:17 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 7+ messages in thread From: Michael Paquier @ 2026-10-14 01:17 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 <ilya.evdokimov@tantorlabs.com> Discussion: https://postgr.es/m/20d6689e-f490-4ca7-a92f-e92f691ba07e@tantorlabs.com Backpatch-through: 14 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/6d4607e886a083f7cddb121a84f6d8ee23addd6d Modified Files -------------- src/backend/statistics/mvdistinct.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Release memory allocated by ndistinct_for_combination() @ 2026-10-14 01:17 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 7+ messages in thread From: Michael Paquier @ 2026-10-14 01:17 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 <ilya.evdokimov@tantorlabs.com> Discussion: https://postgr.es/m/20d6689e-f490-4ca7-a92f-e92f691ba07e@tantorlabs.com Backpatch-through: 14 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/f51585330242584306decf2bd526e539876929fe Modified Files -------------- src/backend/statistics/mvdistinct.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Release memory allocated by ndistinct_for_combination() @ 2026-10-14 01:17 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 7+ messages in thread From: Michael Paquier @ 2026-10-14 01:17 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 <ilya.evdokimov@tantorlabs.com> Discussion: https://postgr.es/m/20d6689e-f490-4ca7-a92f-e92f691ba07e@tantorlabs.com Backpatch-through: 14 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/942266c7f41a897a93b9c1019dc258cf0fd642b3 Modified Files -------------- src/backend/statistics/mvdistinct.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Release memory allocated by ndistinct_for_combination() @ 2026-10-14 01:17 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 7+ messages in thread From: Michael Paquier @ 2026-10-14 01:17 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 <ilya.evdokimov@tantorlabs.com> Discussion: https://postgr.es/m/20d6689e-f490-4ca7-a92f-e92f691ba07e@tantorlabs.com 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(+) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Release memory allocated by ndistinct_for_combination() @ 2026-10-14 01:17 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 7+ messages in thread From: Michael Paquier @ 2026-10-14 01:17 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 <ilya.evdokimov@tantorlabs.com> Discussion: https://postgr.es/m/20d6689e-f490-4ca7-a92f-e92f691ba07e@tantorlabs.com Backpatch-through: 14 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/050ad7edbec6964557e439cfebca81fa9514d3cd Modified Files -------------- src/backend/statistics/mvdistinct.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Release memory allocated by ndistinct_for_combination() @ 2026-10-14 01:17 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 7+ messages in thread From: Michael Paquier @ 2026-10-14 01:17 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 <ilya.evdokimov@tantorlabs.com> Discussion: https://postgr.es/m/20d6689e-f490-4ca7-a92f-e92f691ba07e@tantorlabs.com Backpatch-through: 14 Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/ec6780c59e815950aa67cca77f051be238fdb72b Modified Files -------------- src/backend/statistics/mvdistinct.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Release memory allocated by ndistinct_for_combination() @ 2026-10-14 01:17 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 7+ messages in thread From: Michael Paquier @ 2026-10-14 01:17 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 <ilya.evdokimov@tantorlabs.com> Discussion: https://postgr.es/m/20d6689e-f490-4ca7-a92f-e92f691ba07e@tantorlabs.com Backpatch-through: 14 Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/205f40f5b27392b54a7ffba3059522ccc2a5d269 Modified Files -------------- src/backend/statistics/mvdistinct.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2026-10-14 01:17 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-10-14 01:17 pgsql: Release memory allocated by ndistinct_for_combination() Michael Paquier <michael@paquier.xyz> 2026-10-14 01:17 pgsql: Release memory allocated by ndistinct_for_combination() Michael Paquier <michael@paquier.xyz> 2026-10-14 01:17 pgsql: Release memory allocated by ndistinct_for_combination() Michael Paquier <michael@paquier.xyz> 2026-10-14 01:17 pgsql: Release memory allocated by ndistinct_for_combination() Michael Paquier <michael@paquier.xyz> 2026-10-14 01:17 pgsql: Release memory allocated by ndistinct_for_combination() Michael Paquier <michael@paquier.xyz> 2026-10-14 01:17 pgsql: Release memory allocated by ndistinct_for_combination() Michael Paquier <michael@paquier.xyz> 2026-10-14 01:17 pgsql: Release memory allocated by ndistinct_for_combination() Michael Paquier <michael@paquier.xyz>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox