Add path column to pg_backend_memory_contexts view
authorDavid Rowley <[email protected]>
Thu, 25 Jul 2024 03:03:28 +0000 (15:03 +1200)
committerDavid Rowley <[email protected]>
Thu, 25 Jul 2024 03:03:28 +0000 (15:03 +1200)
commit32d3ed8165f821f6994c95230a9a4b2ff0ce9f12
treee0372387e67360550b55183841950833cfe478c9
parent64c39bd5047e6ee045bbc80ea1399feb59cd2b53
Add path column to pg_backend_memory_contexts view

"path" provides a reliable method of determining the parent/child
relationships between memory contexts.  Previously this could be done in
a non-reliable way by writing a recursive query and joining the "parent"
and "name" columns.  This wasn't reliable as the names were not unique,
which could result in joining to the wrong parent.

To make this reliable, "path" stores an array of numerical identifiers
starting with the identifier for TopLevelMemoryContext.  It contains an
element for each intermediate parent between that and the current context.

Incompatibility: Here we also adjust the "level" column to make it
1-based rather than 0-based.  A 1-based level provides a convenient way
to access elements in the "path" array. e.g. path[level] gives the
identifier for the current context.

Identifiers are not stable across multiple evaluations of the view.  In
an attempt to make these more stable for ad-hoc queries, the identifiers
are assigned breadth-first.  Contexts closer to TopLevelMemoryContext
are less likely to change between queries and during queries.

Author: Melih Mutlu <[email protected]>
Discussion: https://postgr.es/m/CAGPVpCThLyOsj3e_gYEvLoHkr5w=tadDiN_=z2OwsK3VJppeBA@mail.gmail.com
Reviewed-by: Andres Freund, Stephen Frost, Atsushi Torikoshi,
Reviewed-by: Michael Paquier, Robert Haas, David Rowley
doc/src/sgml/system-views.sgml
src/backend/utils/adt/mcxtfuncs.c
src/include/catalog/catversion.h
src/include/catalog/pg_proc.dat
src/include/nodes/memnodes.h
src/test/regress/expected/rules.out
src/test/regress/expected/sysviews.out
src/test/regress/sql/sysviews.sql