Re: Parent/child context relation in pg_get_backend_memory_contexts() - Mailing list pgsql-hackers

From Melih Mutlu
Subject Re: Parent/child context relation in pg_get_backend_memory_contexts()
Date
Msg-id CAGPVpCQhkzU8Usze1yUPqtnYy2xwONVk=T3LYbFFvmw0c6tQrA@mail.gmail.com
Whole thread Raw
In response to Re: Parent/child context relation in pg_get_backend_memory_contexts()  (David Rowley <dgrowleyml@gmail.com>)
List pgsql-hackers
Hi David,

David Rowley <dgrowleyml@gmail.com>, 5 Tem 2024 Cum, 11:06 tarihinde şunu yazdı:
With the order you have it, that query could be expressed as:

WITH c AS (SELECT * FROM pg_backend_memory_contexts)
SELECT c1.*
FROM c c1, c c2
WHERE c2.name = 'CacheMemoryContext'
AND c1.path[c2.level + 1] = c2.path[c2.level + 1];

Whereas, with the way I had in mind, it would need to look like:

WITH c AS (SELECT * FROM pg_backend_memory_contexts)
SELECT c1.*
FROM c c1, c c2
WHERE c2.name = 'CacheMemoryContext'
AND c1.path[c1.level - c2.level + 1] = c2.path[1];

I kind of think the latter makes more sense, as if for some reason you
know the level and context ID of the context you're looking up, you
can do:

I liked the fact that a context would always be at the same position, level+1, in all context_ids arrays of its children. But what you described makes sense as well, so I changed the order.

I also imagined "path" would be called "context_ids". I thought that
might better indicate what the column is without consulting the
documentation.

Done.

 
I think it might also be easier to document what context_ids is:

"Array of transient identifiers to describe the memory context
hierarchy. The first array element contains the ID for the current
context and each subsequent ID is the parent of the previous element.
Note that these IDs are unstable between multiple invocations of the
view.  See the example query below for advice on how to use this
column effectively."

Done.

 
There are also a couple of white space issues with the patch.  If
you're in a branch with the patch applied directly onto master, then
"git diff master --check" should show where they are.

Done.

Thanks,
--
Melih Mutlu
Microsoft
Attachment

pgsql-hackers by date:

Previous
From: Bertrand Drouvot
Date:
Subject: Re: Restart pg_usleep when interrupted
Next
From: Junwang Zhao
Date:
Subject: Re: Address the -Wuse-after-free warning in ATExecAttachPartition()