Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-28 Thread David Rowley
On Mon, 29 Jul 2024 at 04:31, Tom Lane wrote: > It is not clear to me exactly which of these pointers should be > presumed to be possibly-null, but certainly testing ident after > storing through it is pretty pointless. Maybe what was intended > was > > - if (ident && strcmp(*name, "dynahas

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-28 Thread Tom Lane
David Rowley writes: > I ended up fixing that another way as the above seems to be casting > away the const for those variables. Instead, I changed the signature > of the function to: > static void get_memory_context_name_and_ident(MemoryContext context, > const char **const name, const char **co

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-24 Thread David Rowley
On Tue, 23 Jul 2024 at 22:14, Melih Mutlu wrote: > 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, > +

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-24 Thread David Rowley
On Wed, 24 Jul 2024 at 21:47, David Rowley wrote: > I've only had a quick look so far, but I think the patch is now in the > right shape. Unless there's some objections to how things are being > done in v10, I plan to commit this in the next few days... modulo any > minor adjustments. I reviewed

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-24 Thread David Rowley
On Tue, 23 Jul 2024 at 22:14, Melih Mutlu wrote: > 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, > +

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-23 Thread Melih Mutlu
Hi David, David Rowley , 15 Tem 2024 Pzt, 14:38 tarihinde şunu yazdı: > On Sat, 13 Jul 2024 at 10:12, Melih Mutlu wrote: > > I updated documentation for path and level columns and also fixed the > tests as level starts from 1. > > Thanks for updating. > > + The path column can be useful to bui

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-16 Thread Robert Haas
On Mon, Jul 15, 2024 at 8:22 PM David Rowley wrote: > > That said, if you want to go with the integer > > IDs and want to spend more time massaging it, I also think that's > > fine. I simply don't believe it's the only way forward here. YMMV, but > > my opinion is that none of these approaches hav

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-15 Thread David Rowley
On Tue, 16 Jul 2024 at 06:19, Robert Haas wrote: > I'm not against what you're trying to do here, but I feel like you > might be over-engineering it. I don't think there was anything really > wrong with what Melih was doing, and I don't think there's anything > really wrong with converting the pat

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-15 Thread Robert Haas
On Mon, Jul 15, 2024 at 6:44 AM David Rowley wrote: > Unfortunately, this wouldn't align with the goals of the patch. Going > back to Melih's opening paragraph in the initial email, he mentions > that there's currently no *reliable* way to determine the parent/child > relationship in this view. >

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-15 Thread Robert Haas
On Fri, Jul 12, 2024 at 6:33 PM Melih Mutlu wrote: > I just ran the below to see if we have any context with the same level and > name. > > postgres=# select level, name, count(*) from pg_backend_memory_contexts group > by level, name having count(*)>1; > level |name | count > ---+

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-15 Thread David Rowley
On Sat, 13 Jul 2024 at 10:12, Melih Mutlu wrote: > I updated documentation for path and level columns and also fixed the tests > as level starts from 1. Thanks for updating. + The path column can be useful to build + parent/child relation between memory contexts. For example, the following

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-15 Thread David Rowley
On Sat, 13 Jul 2024 at 10:33, Melih Mutlu wrote: > I've been also thinking if we should still have the parent column, as finding > out the parent is also possible via looking into the path. What do you think? I think we should probably consider removing it. Let's think about that later. I don't

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-15 Thread David Rowley
On Fri, 12 Jul 2024 at 08:09, Robert Haas wrote: > Do we ever have contexts with the same name at the same level? Could > we just make the path an array of strings, so that you could then say > something like this... > > SELECT * FROM pg_backend_memory_contexts where path[2] = 'CacheMemoryContext'

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-12 Thread Melih Mutlu
Hi Robert, Robert Haas , 11 Tem 2024 Per, 23:09 tarihinde şunu yazdı: > > Ideally, no CTE would be needed here, but unfortunately, there's no > > way to know the CacheMemoryContext's ID beforehand. We could make the > > ID more stable if we did a breadth-first traversal of the context. > > i.e.,

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-12 Thread Melih Mutlu
Hi David, Thanks for v8 patch. Please see attached v9. David Rowley , 11 Tem 2024 Per, 04:16 tarihinde şunu yazdı: > I did a bit more work in the attached. I changed "level" to be > 1-based and because it's the column before "path" I find it much more > intuitive (assuming no prior knowledge) t

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-11 Thread Robert Haas
On Wed, Jul 10, 2024 at 9:16 PM David Rowley wrote: > Melih and I talked about this in a meeting yesterday evening. I think > I'm about on the fence about having the IDs in leaf-to-root or > root-to-leaf. My main concern about which order is chosen is around > how easy it is to write hierarchical

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-10 Thread David Rowley
On Thu, 11 Jul 2024 at 09:19, Robert Haas wrote: > FWIW, I would have done what Melih did. A path normally is listed in > root-to-leaf order, not leaf-to-root. Melih and I talked about this in a meeting yesterday evening. I think I'm about on the fence about having the IDs in leaf-to-root or root

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-10 Thread Robert Haas
On Fri, Jul 5, 2024 at 4:06 AM David Rowley wrote: > I've been wondering about the order of the "path" column. When we > talked, I had in mind that the TopMemoryContext should always be at > the end of the array rather than the start, but I see you've got it > the other way around. FWIW, I would

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-10 Thread Robert Haas
On Wed, Apr 3, 2024 at 7:34 PM Michael Paquier wrote: > I've been re-reading the patch again to remember what this is about, > and I'm OK with having this "path" column in the catalog. However, > I'm somewhat confused by the choice of having a temporary number that > shows up in the catalog repre

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-09 Thread Melih Mutlu
Hi David, David Rowley , 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.pat

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-05 Thread David Rowley
On Wed, 3 Jul 2024 at 01:08, Melih Mutlu wrote: > An example query to get total used bytes including children by using level > info would look like: > > WITH contexts AS ( > SELECT * FROM pg_backend_memory_contexts > ) > SELECT sum(total_bytes) > FROM contexts > WHERE path[( SELECT level+1 FROM c

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-07-02 Thread Melih Mutlu
Hi hackers, David Rowley , 4 Nis 2024 Per, 04:44 tarihinde şunu yazdı: > My view on this is that there are a couple of things with the patch > which could be considered separately: > > 1. Should we have a context_id in the view? > 2. Should we also have an array of all parents? > I discussed the

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-04-03 Thread David Rowley
On Thu, 4 Apr 2024 at 12:34, Michael Paquier wrote: > I've been re-reading the patch again to remember what this is about, > and I'm OK with having this "path" column in the catalog. However, > I'm somewhat confused by the choice of having a temporary number that > shows up in the catalog represe

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-04-03 Thread Michael Paquier
On Wed, Apr 03, 2024 at 04:20:39PM +0300, Melih Mutlu wrote: > Michael Paquier , 14 Şub 2024 Çar, 10:23 tarihinde > şunu yazdı: >> I was reading the patch, and using int[] as a representation of the >> path of context IDs up to the top-most parent looks a bit strange to >> me, with the relationship

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-04-03 Thread Andres Freund
Hi, On 2024-02-14 16:23:38 +0900, Michael Paquier wrote: > It is possible to retrieve this information some WITH RECURSIVE as well, as > mentioned upthread. Perhaps we could consider documenting these tricks? I think it's sufficiently hard that it's not a reasonable way to do this. Greetings,

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-04-03 Thread Melih Mutlu
Hi, Michael Paquier , 14 Şub 2024 Çar, 10:23 tarihinde şunu yazdı: > On Fri, Jan 19, 2024 at 05:41:45PM +0900, torikoshia wrote: > > We already have additional description below the table which explains > each > > column of the system view. For example pg_locks: > > https://www.postgresql.org/doc

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-02-13 Thread Michael Paquier
On Fri, Jan 19, 2024 at 05:41:45PM +0900, torikoshia wrote: > We already have additional description below the table which explains each > column of the system view. For example pg_locks: > https://www.postgresql.org/docs/devel/view-pg-locks.html I was reading the patch, and using int[] as a repre

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-01-19 Thread torikoshia
On 2024-01-16 18:41, Melih Mutlu wrote: Hi, Thanks for reviewing. torikoshia , 10 Oca 2024 Çar, 09:37 tarihinde şunu yazdı: + + + context_id int4 + + + Current context id. Note that the context id is a temporary id and may + change in each invocation

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-01-16 Thread Melih Mutlu
Hi, Thanks for reviewing. torikoshia , 10 Oca 2024 Çar, 09:37 tarihinde şunu yazdı: > > + > > + > role="column_definition"> > > + context_id int4 > > + > > + > > + Current context id. Note that the context id is a temporary id > > and may > > + change in

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-01-09 Thread torikoshia
On 2024-01-03 20:40, Melih Mutlu wrote: Hi, Thanks for reviewing. Please find the updated patch attached. torikoshia , 4 Ara 2023 Pzt, 07:43 tarihinde şunu yazdı: I reviewed v3 patch and here are some minor comments: + + + path int4 Should 'int4' be 'int4[]'? Other system

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2024-01-03 Thread Melih Mutlu
Hi, Thanks for reviewing. Please find the updated patch attached. torikoshia , 4 Ara 2023 Pzt, 07:43 tarihinde şunu yazdı: > I reviewed v3 patch and here are some minor comments: > > > + > > + > role="column_definition"> > > + path int4 > > Should 'int4' be 'int4[]'? > Other sys

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2023-12-03 Thread torikoshia
Thanks for working on this improvement! On 2023-10-23 21:02, Melih Mutlu wrote: Hi, Thanks for reviewing. Attached the updated patch v3. I reviewed v3 patch and here are some minor comments: + + role="column_definition"> + path int4 Should 'int4' be 'int4[]'? Other system

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2023-10-23 Thread Melih Mutlu
Hi, Thanks for reviewing. Attached the updated patch v3. Andres Freund , 12 Eki 2023 Per, 19:23 tarihinde şunu yazdı: > > Here how pg_backend_memory_contexts would look like with this patch: > > > > postgres=# SELECT name, id, parent, parent_id, path > > FROM pg_backend_memory_contexts > > ORDER

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2023-10-19 Thread Stephen Frost
Greetings, * Andres Freund (and...@anarazel.de) wrote: > On 2023-10-18 15:53:30 -0400, Stephen Frost wrote: > > > Here how pg_backend_memory_contexts would look like with this patch: > > > > > > postgres=# SELECT name, id, parent, parent_id, path > > > FROM pg_backend_memory_contexts > > > ORDER

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2023-10-18 Thread Andres Freund
Hi, On 2023-10-18 15:53:30 -0400, Stephen Frost wrote: > > Here how pg_backend_memory_contexts would look like with this patch: > > > > postgres=# SELECT name, id, parent, parent_id, path > > FROM pg_backend_memory_contexts > > ORDER BY total_bytes DESC LIMIT 10; > > name | id

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2023-10-18 Thread Stephen Frost
Greetings, * Melih Mutlu (m.melihmu...@gmail.com) wrote: > Melih Mutlu , 16 Haz 2023 Cum, 17:03 tarihinde şunu > yazdı: > > > With this change, here's a query to find how much space used by each > > context including its children: > > > > > WITH RECURSIVE cte AS ( > > > SELECT id, total_bytes

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2023-10-12 Thread Andres Freund
Hi, On 2023-08-04 21:16:49 +0300, Melih Mutlu wrote: > Melih Mutlu , 16 Haz 2023 Cum, 17:03 tarihinde şunu > yazdı: > > > With this change, here's a query to find how much space used by each > > context including its children: > > > > > WITH RECURSIVE cte AS ( > > > SELECT id, total_bytes, id

Re: Parent/child context relation in pg_get_backend_memory_contexts()

2023-08-04 Thread Melih Mutlu
Hi hackers, Melih Mutlu , 16 Haz 2023 Cum, 17:03 tarihinde şunu yazdı: > With this change, here's a query to find how much space used by each > context including its children: > > > WITH RECURSIVE cte AS ( > > SELECT id, total_bytes, id as root, name as root_name > > FROM memory_contexts