From 17b3c57b53f53b504385ddde722a2ad0c88b2de5 Mon Sep 17 00:00:00 2001
From: Melih Mutlu <m.melihmutlu@gmail.com>
Date: Tue, 30 Jul 2024 19:20:34 +0300
Subject: [PATCH v1] Remove parent from pg_backend_memory_context

After adding path column into pg_backend_memory_context view wih commit
32d3ed8165, parent of a memory context can be found using the path
array.
---
 src/backend/utils/adt/mcxtfuncs.c   | 30 +++++++++--------------------
 src/include/catalog/pg_proc.dat     |  6 +++---
 src/test/regress/expected/rules.out |  1 -
 3 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/src/backend/utils/adt/mcxtfuncs.c b/src/backend/utils/adt/mcxtfuncs.c
index 5905958c1f..34d70199fc 100644
--- a/src/backend/utils/adt/mcxtfuncs.c
+++ b/src/backend/utils/adt/mcxtfuncs.c
@@ -93,7 +93,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];
@@ -154,18 +154,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 +173,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);
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 06b2f4ba66..ee780f81fb 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -8317,9 +8317,9 @@
   proname => 'pg_get_backend_memory_contexts', prorows => '100',
   proretset => 't', provolatile => 'v', proparallel => 'r',
   prorettype => 'record', proargtypes => '',
-  proallargtypes => '{text,text,text,text,int4,_int4,int8,int8,int8,int8,int8}',
-  proargmodes => '{o,o,o,o,o,o,o,o,o,o,o}',
-  proargnames => '{name, ident, parent, type, level, path, total_bytes, total_nblocks, free_bytes, free_chunks, used_bytes}',
+  proallargtypes => '{text,text,text,int4,_int4,int8,int8,int8,int8,int8}',
+  proargmodes => '{o,o,o,o,o,o,o,o,o,o}',
+  proargnames => '{name, ident, type, level, path, total_bytes, total_nblocks, free_bytes, free_chunks, used_bytes}',
   prosrc => 'pg_get_backend_memory_contexts' },
 
 # logging memory contexts of the specified backend
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 5201280669..d3aec87f1c 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -1305,7 +1305,6 @@ pg_available_extensions| SELECT e.name,
      LEFT JOIN pg_extension x ON ((e.name = x.extname)));
 pg_backend_memory_contexts| SELECT name,
     ident,
-    parent,
     type,
     level,
     path,
-- 
2.34.1

