aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/mcxtfuncs.c
diff options
context:
space:
mode:
authorDavid Rowley <drowley@postgresql.org>2024-08-12 15:42:16 +1200
committerDavid Rowley <drowley@postgresql.org>2024-08-12 15:42:16 +1200
commitf0d11275954719fd5d0281d4135e5c78de46e099 (patch)
tree6c8b6ad56624f1959a36d77e8bb4163bbe55e363 /src/backend/utils/adt/mcxtfuncs.c
parent3f44959f47460fb350d25d760cf2384f9aa14e9a (diff)
downloadpostgresql-f0d11275954719fd5d0281d4135e5c78de46e099.tar.gz
postgresql-f0d11275954719fd5d0281d4135e5c78de46e099.zip
Remove "parent" column from pg_backend_memory_contexts
32d3ed816 added the "path" column to pg_backend_memory_contexts to allow a stable method of obtaining the parent MemoryContext of a given row in the view. Using the "path" column is now the preferred method of obtaining the parent row. Previously, any queries which were self-joining to this view using the "name" and "parent" columns could get incorrect results due to the fact that names are not unique. Here we aim to explicitly break such queries so that they can be corrected and use the "path" column instead. It is possible that there are more innocent users of the parent column that just need an indication of the parent and having to write out a self-joining CTE may be an unnecessary hassle for those cases. Let's remove the column for now and see if anyone comes back with any complaints. This does seem like a good time to attempt to get rid of the column as we still have around 1 year to revert this if someone comes back with a valid complaint. Plus this view is new to v14 and is quite niche, so perhaps not many people will be affected. Author: Melih Mutlu <m.melihmutlu@gmail.com> Discussion: https://postgr.es/m/CAGPVpCT7NOe4fZXRL8XaoxHpSXYTu6GTpULT_3E-HT9hzjoFRA@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/mcxtfuncs.c')
-rw-r--r--src/backend/utils/adt/mcxtfuncs.c65
1 files changed, 21 insertions, 44 deletions
diff --git a/src/backend/utils/adt/mcxtfuncs.c b/src/backend/utils/adt/mcxtfuncs.c
index 5905958c1f5..6a6634e1cda 100644
--- a/src/backend/utils/adt/mcxtfuncs.c
+++ b/src/backend/utils/adt/mcxtfuncs.c
@@ -41,28 +41,6 @@ typedef struct MemoryContextId
} MemoryContextId;
/*
- * get_memory_context_name_and_ident
- * Populate *name and *ident from the name and ident from 'context'.
- */
-static void
-get_memory_context_name_and_ident(MemoryContext context, const char **const name,
- const char **const ident)
-{
- *name = context->name;
- *ident = context->ident;
-
- /*
- * To be consistent with logging output, we label dynahash contexts with
- * just the hash table name as with MemoryContextStatsPrint().
- */
- if (*ident == NULL && strcmp(*name, "dynahash") == 0)
- {
- *name = *ident;
- *ident = NULL;
- }
-}
-
-/*
* int_list_to_array
* Convert an IntList to an array of INT4OIDs.
*/
@@ -93,7 +71,7 @@ PutMemoryContextsStatsTupleStore(Tuplestorestate *tupstore,
TupleDesc tupdesc, MemoryContext context,
HTAB *context_id_lookup)
{
-#define PG_GET_BACKEND_MEMORY_CONTEXTS_COLS 11
+#define PG_GET_BACKEND_MEMORY_CONTEXTS_COLS 10
Datum values[PG_GET_BACKEND_MEMORY_CONTEXTS_COLS];
bool nulls[PG_GET_BACKEND_MEMORY_CONTEXTS_COLS];
@@ -128,7 +106,18 @@ PutMemoryContextsStatsTupleStore(Tuplestorestate *tupstore,
memset(values, 0, sizeof(values));
memset(nulls, 0, sizeof(nulls));
- get_memory_context_name_and_ident(context, &name, &ident);
+ name = context->name;
+ ident = context->ident;
+
+ /*
+ * To be consistent with logging output, we label dynahash contexts with
+ * just the hash table name as with MemoryContextStatsPrint().
+ */
+ if (ident && strcmp(name, "dynahash") == 0)
+ {
+ name = ident;
+ ident = NULL;
+ }
if (name)
values[0] = CStringGetTextDatum(name);
@@ -154,18 +143,6 @@ PutMemoryContextsStatsTupleStore(Tuplestorestate *tupstore,
else
nulls[1] = true;
- if (context->parent)
- {
- const char *parent_name,
- *parent_ident;
-
- get_memory_context_name_and_ident(context->parent, &parent_name,
- &parent_ident);
- values[2] = CStringGetTextDatum(parent_name);
- }
- else
- nulls[2] = true;
-
switch (context->type)
{
case T_AllocSetContext:
@@ -185,14 +162,14 @@ PutMemoryContextsStatsTupleStore(Tuplestorestate *tupstore,
break;
}
- values[3] = CStringGetTextDatum(type);
- values[4] = Int32GetDatum(list_length(path)); /* level */
- values[5] = int_list_to_array(path);
- values[6] = Int64GetDatum(stat.totalspace);
- values[7] = Int64GetDatum(stat.nblocks);
- values[8] = Int64GetDatum(stat.freespace);
- values[9] = Int64GetDatum(stat.freechunks);
- values[10] = Int64GetDatum(stat.totalspace - stat.freespace);
+ values[2] = CStringGetTextDatum(type);
+ values[3] = Int32GetDatum(list_length(path)); /* level */
+ values[4] = int_list_to_array(path);
+ values[5] = Int64GetDatum(stat.totalspace);
+ values[6] = Int64GetDatum(stat.nblocks);
+ values[7] = Int64GetDatum(stat.freespace);
+ values[8] = Int64GetDatum(stat.freechunks);
+ values[9] = Int64GetDatum(stat.totalspace - stat.freespace);
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
list_free(path);