Release memory allocated by dependency_degree
authorTomas Vondra <[email protected]>
Mon, 20 Sep 2021 23:13:11 +0000 (01:13 +0200)
committerTomas Vondra <[email protected]>
Thu, 23 Sep 2021 16:55:22 +0000 (18:55 +0200)
commitd77e085afd52e9023075288ba95cf3280e273c2d
treea30873fcc1f1f0bd33b4f9dcd0fde8f0f4e6e840
parent3aac99068cd7abe9d6fbc8c0faa361d75f7d0bfc
Release memory allocated by dependency_degree

Calculating degree of a functional dependency may allocate a lot of
memory - we have released mot of the explicitly allocated memory, but
e.g. detoasted varlena values were left behind. That may be an issue,
because we consider a lot of dependencies (all combinations), and the
detoasting may happen for each one again.

Fixed by calling dependency_degree() in a dedicated context, and
resetting it after each call. We only need the calculated dependency
degree, so we don't need to copy anything.

Backpatch to PostgreSQL 10, where extended statistics were introduced.

Backpatch-through: 10
Discussion: https://www.postgresql.org/message-id/20210915200928.GP831%40telsasoft.com
src/backend/statistics/dependencies.c