mem context is not reset between extended stats
Justin Pryzby <pryzby@telsasoft.com>
From: Justin Pryzby <pryzby@telsasoft.com>
To: Tomas Vondra <tomas.vondra@enterprisedb.com>
Cc: pgsql-hackers@postgresql.org
Date: 2021-09-15T20:09:28Z
Lists: pgsql-hackers
Attachments
- 0001-stx-do-not-leak-memory-for-each-stats-obj.patch (text/x-diff)
Memory allocation appeared be O(1) WRT the number of statistics objects, which
was not expected to me. This is true in v13 (and probably back to v10).
It seems to work fine to reset the memory context within the loop, so long as
the statslist is allocated in the parent context.
|DROP TABLE t; CREATE TABLE t AS SELECT i, i+1 AS a, i+2 AS b, i+3 AS c, i+4 AS d, i+5 AS e FROM generate_series(1,99999)i;
|SELECT format('CREATE STATISTICS sta%s (ndistinct) ON a,(1+b),(2+c),(3+d),(4+e) FROM t', a) FROM generate_series(1,9)a\gexec
|SET log_statement_stats=on; SET client_min_messages=debug; ANALYZE t;
|=> 369432 kB max resident size
|SELECT format('CREATE STATISTICS sta%s (ndistinct) ON a,b,c,d,e FROM t', a) FROM generate_series(1,33)a\gexec
|SET log_statement_stats=on; SET client_min_messages=debug; ANALYZE t;
|=> 1284368 kB max resident size
Commits
-
Release memory allocated by dependency_degree
- d77e085afd52 10.19 landed
- 4487a7def3ae 11.14 landed
- 4185632e93c1 12.9 landed
- c0386f403a83 13.5 landed
- abb2f9144ba1 14.0 landed
- ad8a166ca868 15.0 landed
-
Free memory after building each statistics object
- 3aac99068cd7 10.19 landed
- ac7290a20ec5 11.14 landed
- 16d394c05065 12.9 landed
- b564eb0181e6 13.5 landed
- bb7628e55eda 14.0 landed
- 83772cc78e03 15.0 landed