Re: Parent/child context relation in pg_get_backend_memory_contexts()

From: Melih Mutlu <m(dot)melihmutlu(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, torikoshia <torikoshia(at)oss(dot)nttdata(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, Stephen Frost <sfrost(at)snowman(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Parent/child context relation in pg_get_backend_memory_contexts()
Date: 2024-07-09 10:56:32
Message-ID: CAGPVpCQhkzU8Usze1yUPqtnYy2xwONVk=T3LYbFFvmw0c6tQrA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi David,

David Rowley <dgrowleyml(at)gmail(dot)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 Content-Type Size
v7-0002-Add-total_bytes_including_children-column.patch application/octet-stream 7.5 KB
v7-0001-context_ids-column-in-pg_backend_memory_contexts.patch application/octet-stream 10.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Junwang Zhao 2024-07-09 10:57:48 Re: Address the -Wuse-after-free warning in ATExecAttachPartition()
Previous Message Bertrand Drouvot 2024-07-09 10:44:05 Re: Restart pg_usleep when interrupted