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: Robert Haas <robertmhaas(at)gmail(dot)com>, 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-23 10:14:09
Message-ID: CAGPVpCRh_CrPRPcrUuOsheEmPR6mpFGVum9cUtH81oG3rnOO=g@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>, 15 Tem 2024 Pzt, 14:38 tarihinde şunu
yazdı:

> On Sat, 13 Jul 2024 at 10:12, Melih Mutlu <m(dot)melihmutlu(at)gmail(dot)com> wrote:
> > I updated documentation for path and level columns and also fixed the
> tests as level starts from 1.
>
> Thanks for updating.
>
> + The <structfield>path</structfield> column can be useful to build
> + parent/child relation between memory contexts. For example, the
> following
> + query calculates the total number of bytes used by a memory context
> and its
> + child contexts:
>
> "a memory context" doesn't quite sound specific enough. Let's say what
> the query is doing exactly.
>

Changed "a memory context" with "CacheMemoryContext".

> +<programlisting>
> +WITH memory_contexts AS (
> + SELECT *
> + FROM pg_backend_memory_contexts
> +)
> +SELECT SUM(total_bytes)
> +FROM memory_contexts
> +WHERE ARRAY[(SELECT path[array_length(path, 1)] FROM memory_contexts
> WHERE name = 'CacheMemoryContext')] &lt;@ path;
>
> I don't think that example query is the most simple example. Isn't it
> better to use the most simple form possible to express that?
>
> I think it would be nice to give an example of using "level" as an
> index into "path"
>
> WITH c AS (SELECT * FROM pg_backend_memory_contexts)
> SELECT sum(c1.total_bytes)
> FROM c c1, c c2
> WHERE c2.name = 'CacheMemoryContext'
> AND c1.path[c2.level] = c2.path[c2.level];
>

I changed the queries in the documentation and regression test to the ones
similar to the above query that you shared.

+ /*
> + * Queue up all the child contexts of this level for the next
> + * iteration of the outer loop.
> + */
>
> That outer loop is gone.
>

Removed that part.

> Also, this was due to my hasty writing of the patch. I named the
> function get_memory_context_name_and_indent. I meant to write "ident".
> If we did get rid of the "parent" column, I'd not see any need to keep
> that function. The logic could just be put in
> PutMemoryContextsStatsTupleStore(). I just did it that way to avoid
> the repeat.
>

Fixed the name. Also I needed to cast parameters when calling that function
as below to get rid of some warnings.

+ get_memory_context_name_and_ident(context,
+
(const char **)&name,
+
(const char **) &ident);

Thanks,
--
Melih Mutlu
Microsoft

Attachment Content-Type Size
v10-0001-Add-path-column-into-pg_backend_memory_contexts.patch application/octet-stream 16.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2024-07-23 10:31:07 Re: CI, macports, darwin version problems
Previous Message Marlene Reiterer 2024-07-23 09:45:00 Re: Docs: Order of json aggregate functions