mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	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
			
			
This commit is contained in:
		@@ -40,28 +40,6 @@ typedef struct MemoryContextId
 | 
			
		||||
	int			context_id;
 | 
			
		||||
}			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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user