Re: Huge memory consumption on partitioned table with FKs

2021-03-11 Thread Tatsuro Yamada
On 2021/03/12 2:44, Tom Lane wrote: I wrote: Now, maybe it's a coincidence that husky failed on a partitioned-foreign-key test right after this patch went in, but I bet not. Since husky runs CLOBBER_CACHE_ALWAYS, it looks to me like we've overlooked some cache-reset scenario or other. After r

Re: Huge memory consumption on partitioned table with FKs

2021-03-11 Thread Tom Lane
I wrote: > Now, maybe it's a coincidence that husky failed on a > partitioned-foreign-key test right after this patch went in, but I bet > not. Since husky runs CLOBBER_CACHE_ALWAYS, it looks to me like we've > overlooked some cache-reset scenario or other. After reproducing it here, that *is* a

Re: Huge memory consumption on partitioned table with FKs

2021-03-11 Thread Tom Lane
Tatsuro Yamada writes: > Thanks for fixing the problem! :-D Hmm, I'm not sure we're done with this patch: https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=husky&dt=2021-03-10%2021%3A09%3A32 The critical log extract is 2021-03-11 05:10:13.012 CET [21574:1082] pg_regress/foreign_key LOG:

Re: Huge memory consumption on partitioned table with FKs

2021-03-10 Thread Tatsuro Yamada
On 2021/03/11 9:39, Amit Langote wrote: On Thu, Mar 11, 2021 at 4:25 AM Tom Lane wrote: Amit Langote writes: On Wed, Mar 10, 2021 at 8:37 AM Tom Lane wrote: Hmm. So, the key point is that the values coming from the partitioned child table are injected into the test query as parameters, not

Re: Huge memory consumption on partitioned table with FKs

2021-03-10 Thread Keisuke Kuroda
Hi hackers, > > > > I did some cosmetic fooling with this (mostly, rewriting the comments > > YA time) and pushed it. > > Perfect. Thanks for your time on this. > Thank you for your help! I'm glad to solve it. -- Keisuke Kuroda NTT Software Innovation Center keisuke.kuroda.3...@gmail.com

Re: Huge memory consumption on partitioned table with FKs

2021-03-10 Thread Amit Langote
On Thu, Mar 11, 2021 at 4:25 AM Tom Lane wrote: > Amit Langote writes: > > On Wed, Mar 10, 2021 at 8:37 AM Tom Lane wrote: > >> Hmm. So, the key point is that the values coming from the partitioned > >> child table are injected into the test query as parameters, not as > >> column references, t

Re: Huge memory consumption on partitioned table with FKs

2021-03-10 Thread Tom Lane
Amit Langote writes: > On Wed, Mar 10, 2021 at 8:37 AM Tom Lane wrote: >> Hmm. So, the key point is that the values coming from the partitioned >> child table are injected into the test query as parameters, not as >> column references, thus it doesn't matter *to the test query* what >> numbers t

Re: Huge memory consumption on partitioned table with FKs

2021-03-10 Thread Amit Langote
On Wed, Mar 10, 2021 at 8:37 AM Tom Lane wrote: > Amit Langote writes: > > On Fri, Mar 5, 2021 at 6:00 AM Tom Lane wrote: > >> This claim seems false on its face: > >>> All child constraints of a given foreign key constraint can use the > >>> same RI query and the resulting plan, that is, no nee

Re: Huge memory consumption on partitioned table with FKs

2021-03-09 Thread Tom Lane
Amit Langote writes: > On Fri, Mar 5, 2021 at 6:00 AM Tom Lane wrote: >> This claim seems false on its face: >>> All child constraints of a given foreign key constraint can use the >>> same RI query and the resulting plan, that is, no need to create as >>> many copies of the query and the plan as

Re: Huge memory consumption on partitioned table with FKs

2021-03-08 Thread Amit Langote
On Mon, Mar 8, 2021 at 9:53 PM Andy Fan wrote: > On Mon, Mar 8, 2021 at 8:42 PM Amit Langote wrote: >> On Mon, Mar 8, 2021 at 8:39 PM Andy Fan wrote: >> > On Mon, Mar 8, 2021 at 3:43 PM Andy Fan wrote: >> >> My point below is a bit off-topic, but I want to share it here. Since >> >> we impleme

Re: Huge memory consumption on partitioned table with FKs

2021-03-08 Thread Andy Fan
On Mon, Mar 8, 2021 at 8:42 PM Amit Langote wrote: > Hi Andy, > > On Mon, Mar 8, 2021 at 8:39 PM Andy Fan wrote: > > On Mon, Mar 8, 2021 at 3:43 PM Andy Fan > wrote: > >> My point below is a bit off-topic, but I want to share it here. Since > >> we implement a partitioned table in PG with the

Re: Huge memory consumption on partitioned table with FKs

2021-03-08 Thread Amit Langote
Hi Andy, On Mon, Mar 8, 2021 at 8:39 PM Andy Fan wrote: > On Mon, Mar 8, 2021 at 3:43 PM Andy Fan wrote: >> My point below is a bit off-topic, but I want to share it here. Since >> we implement a partitioned table in PG with the inherited class, it has much >> more flexibility than other databa

Re: Huge memory consumption on partitioned table with FKs

2021-03-08 Thread Andy Fan
On Mon, Mar 8, 2021 at 3:43 PM Andy Fan wrote: > > > On Fri, Mar 5, 2021 at 5:00 AM Tom Lane wrote: > >> Amit Langote writes: >> > Updated patch attached. >> >> This claim seems false on its face: >> >> > All child constraints of a given foreign key constraint can use the >> > same RI query and

Re: Huge memory consumption on partitioned table with FKs

2021-03-07 Thread Andy Fan
On Fri, Mar 5, 2021 at 5:00 AM Tom Lane wrote: > Amit Langote writes: > > Updated patch attached. > > This claim seems false on its face: > > > All child constraints of a given foreign key constraint can use the > > same RI query and the resulting plan, that is, no need to create as > > many cop

Re: Huge memory consumption on partitioned table with FKs

2021-03-07 Thread Amit Langote
On Fri, Mar 5, 2021 at 6:00 AM Tom Lane wrote: > Amit Langote writes: > > Updated patch attached. > > This claim seems false on its face: > > > All child constraints of a given foreign key constraint can use the > > same RI query and the resulting plan, that is, no need to create as > > many copi

Re: Huge memory consumption on partitioned table with FKs

2021-03-04 Thread Tom Lane
Amit Langote writes: > Updated patch attached. This claim seems false on its face: > All child constraints of a given foreign key constraint can use the > same RI query and the resulting plan, that is, no need to create as > many copies of the query and the plan as there are partitions, as > hap

Re: Huge memory consumption on partitioned table with FKs

2021-03-03 Thread Alvaro Herrera
On 2021-Mar-03, Amit Langote wrote: > I don't know of any unaddressed comments on the patch, so I've marked > the entry Ready for Committer. Thanks, I'll look at it later this week. -- Álvaro Herrera39°49'30"S 73°17'W #error "Operator lives in the wrong universe" (

Re: Huge memory consumption on partitioned table with FKs

2021-03-03 Thread Amit Langote
Hi David, On Wed, Mar 3, 2021 at 10:21 PM David Steele wrote: > On 12/7/20 10:59 PM, Amit Langote wrote: > > On Tue, Dec 8, 2020 at 12:04 PM Kyotaro Horiguchi > > wrote: > >> At Tue, 8 Dec 2020 01:16:00 +0900, Amit Langote > >> wrote in > >>> On Mon, Dec 7, 2020 at 23:48 Alvaro Herrera > >>>

Re: Huge memory consumption on partitioned table with FKs

2021-03-03 Thread David Steele
On 12/7/20 10:59 PM, Amit Langote wrote: On Tue, Dec 8, 2020 at 12:04 PM Kyotaro Horiguchi wrote: At Tue, 8 Dec 2020 01:16:00 +0900, Amit Langote wrote in On Mon, Dec 7, 2020 at 23:48 Alvaro Herrera wrote: I think this bit about splitting the struct is a distraction. Let's get a patch th

Re: Huge memory consumption on partitioned table with FKs

2021-01-11 Thread Keisuke Kuroda
Hi Amit-san, > Thanks for checking. Indeed, it should have been added to the January > commit-fest. I've added it to the March one: > > https://commitfest.postgresql.org/32/2930/ Thank you for your quick response! -- Keisuke Kuroda NTT Software Innovation Center keisuke.kuroda.3...@gmail.com

Re: Huge memory consumption on partitioned table with FKs

2021-01-07 Thread Amit Langote
Kuroda-san, On Fri, Jan 8, 2021 at 1:02 PM Keisuke Kuroda wrote: > Hi Amit-san, > > I noticed that this patch > (v3-0001-ri_triggers.c-Use-root-constraint-OID-as-key-to-r.patch) > is not registered in the commitfest. I think it needs to be registered for > commit, is that correct? > > I have conf

Re: Huge memory consumption on partitioned table with FKs

2021-01-07 Thread Keisuke Kuroda
Hi Amit-san, I noticed that this patch (v3-0001-ri_triggers.c-Use-root-constraint-OID-as-key-to-r.patch) is not registered in the commitfest. I think it needs to be registered for commit, is that correct? I have confirmed that this patch can be applied to HEAD (master), and that check-world PASS.

Re: Huge memory consumption on partitioned table with FKs

2020-12-08 Thread Amit Langote
On Mon, Dec 7, 2020 at 11:01 PM Amit Langote wrote: > On Fri, Dec 4, 2020 at 12:05 PM Kyotaro Horiguchi > wrote: > > > Also, the comment that was in RI_ConstraintInfo now appears in > > > RI_ConstraintParam, and the new struct (RI_ConstraintInfo) is now > > > undocumented. What is the relationsh

Re: Huge memory consumption on partitioned table with FKs

2020-12-07 Thread Amit Langote
On Tue, Dec 8, 2020 at 12:04 PM Kyotaro Horiguchi wrote: > At Tue, 8 Dec 2020 01:16:00 +0900, Amit Langote > wrote in > > Hi Alvaro, > > > > On Mon, Dec 7, 2020 at 23:48 Alvaro Herrera wrote: > > > > > On 2020-Dec-07, Amit Langote wrote: > > > > > > > On Fri, Dec 4, 2020 at 12:05 PM Kyotaro Hor

Re: Huge memory consumption on partitioned table with FKs

2020-12-07 Thread Kyotaro Horiguchi
At Tue, 8 Dec 2020 01:16:00 +0900, Amit Langote wrote in > Hi Alvaro, > > On Mon, Dec 7, 2020 at 23:48 Alvaro Herrera wrote: > > > On 2020-Dec-07, Amit Langote wrote: > > > > > On Fri, Dec 4, 2020 at 12:05 PM Kyotaro Horiguchi > > > wrote: > > > > > Also, the comment that was in RI_Constrain

Re: Huge memory consumption on partitioned table with FKs

2020-12-07 Thread Amit Langote
Hi Alvaro, On Mon, Dec 7, 2020 at 23:48 Alvaro Herrera wrote: > On 2020-Dec-07, Amit Langote wrote: > > > On Fri, Dec 4, 2020 at 12:05 PM Kyotaro Horiguchi > > wrote: > > > > Also, the comment that was in RI_ConstraintInfo now appears in > > > > RI_ConstraintParam, and the new struct (RI_Constr

Re: Huge memory consumption on partitioned table with FKs

2020-12-07 Thread Alvaro Herrera
On 2020-Dec-07, Amit Langote wrote: > On Fri, Dec 4, 2020 at 12:05 PM Kyotaro Horiguchi > wrote: > > > Also, the comment that was in RI_ConstraintInfo now appears in > > > RI_ConstraintParam, and the new struct (RI_ConstraintInfo) is now > > > undocumented. What is the relationship between those

Re: Huge memory consumption on partitioned table with FKs

2020-12-07 Thread Amit Langote
On Fri, Dec 4, 2020 at 12:05 PM Kyotaro Horiguchi wrote: > > Also, the comment that was in RI_ConstraintInfo now appears in > > RI_ConstraintParam, and the new struct (RI_ConstraintInfo) is now > > undocumented. What is the relationship between those two structs? I > > see that they have pointer

Re: Huge memory consumption on partitioned table with FKs

2020-12-03 Thread Amit Langote
On Fri, Dec 4, 2020 at 2:48 PM Kyotaro Horiguchi wrote: > At Fri, 4 Dec 2020 12:00:09 +0900, Keisuke Kuroda > wrote in > > Hi Amit, > > > > > I have attached a patch in which I've tried to merge the ideas from > > > both my patch and Kuroda-san's. I liked that his patch added > > > conparentid

Re: Huge memory consumption on partitioned table with FKs

2020-12-03 Thread Kyotaro Horiguchi
At Fri, 4 Dec 2020 12:00:09 +0900, Keisuke Kuroda wrote in > Hi Amit, > > > I have attached a patch in which I've tried to merge the ideas from > > both my patch and Kuroda-san's. I liked that his patch added > > conparentid to RI_ConstraintInfo because that saves a needless > > syscache looku

Re: Huge memory consumption on partitioned table with FKs

2020-12-03 Thread Kyotaro Horiguchi
Thanks, but sorry for the confusion. I intended just to show how it looks like if we share RI_ConstraintInfo among partition relations. At Thu, 3 Dec 2020 10:22:47 -0300, Alvaro Herrera wrote in > Hello > > I haven't followed this thread's latest posts, but I'm unclear on the > lifetime of th

Re: Huge memory consumption on partitioned table with FKs

2020-12-03 Thread Keisuke Kuroda
Hi Amit, > I have attached a patch in which I've tried to merge the ideas from > both my patch and Kuroda-san's. I liked that his patch added > conparentid to RI_ConstraintInfo because that saves a needless > syscache lookup for constraints that don't have a parent. I've kept > my idea to comput

Re: Huge memory consumption on partitioned table with FKs

2020-12-03 Thread Kyotaro Horiguchi
At Thu, 3 Dec 2020 21:40:29 +0900, Amit Langote wrote in > On Thu, Dec 3, 2020 at 5:13 PM Kyotaro Horiguchi > wrote: > > At Thu, 3 Dec 2020 16:41:45 +0900, Amit Langote > > wrote in > > > Maybe I misread but I think you did in your email dated Dec 1 where you > > > said: > > > > > > "After a

Re: Huge memory consumption on partitioned table with FKs

2020-12-03 Thread Alvaro Herrera
Hello I haven't followed this thread's latest posts, but I'm unclear on the lifetime of the new struct that's being allocated in TopMemoryContext. At what point are those structs freed? Also, the comment that was in RI_ConstraintInfo now appears in RI_ConstraintParam, and the new struct (RI_Const

Re: Huge memory consumption on partitioned table with FKs

2020-12-03 Thread Amit Langote
On Tue, Dec 1, 2020 at 12:25 PM Corey Huinker wrote: > On Mon, Nov 30, 2020 at 9:48 PM Tom Lane wrote: >> Corey Huinker writes: >> > Given that we're already looking at these checks, I was wondering if this >> > might be the time to consider implementing these checks by directly >> > scanning th

Re: Huge memory consumption on partitioned table with FKs

2020-12-03 Thread Amit Langote
On Thu, Dec 3, 2020 at 5:13 PM Kyotaro Horiguchi wrote: > At Thu, 3 Dec 2020 16:41:45 +0900, Amit Langote > wrote in > > Maybe I misread but I think you did in your email dated Dec 1 where you > > said: > > > > "After an off-list discussion, we confirmed that even in that case the > > patch wor

Re: Huge memory consumption on partitioned table with FKs

2020-12-03 Thread Kyotaro Horiguchi
At Thu, 03 Dec 2020 17:13:16 +0900 (JST), Kyotaro Horiguchi wrote in me> I agree that plans are rather large but the sharable part of the me> RI_ConstraintInfos is 536 bytes, I'm not sure it is small enough me> comparing to the plans. But that has somewhat large footprint.. (See me> the attache

Re: Huge memory consumption on partitioned table with FKs

2020-12-03 Thread Kyotaro Horiguchi
At Thu, 3 Dec 2020 16:41:45 +0900, Amit Langote wrote in > On Thu, Dec 3, 2020 at 2:29 PM Kyotaro Horiguchi > wrote: > > At Thu, 3 Dec 2020 12:27:53 +0900, Amit Langote > > wrote in > > > On Thu, Dec 3, 2020 at 10:15 AM Kyotaro Horiguchi > > > wrote: > > > For the queries on the referencing

Re: Huge memory consumption on partitioned table with FKs

2020-12-02 Thread Amit Langote
On Thu, Dec 3, 2020 at 2:29 PM Kyotaro Horiguchi wrote: > At Thu, 3 Dec 2020 12:27:53 +0900, Amit Langote > wrote in > > On Thu, Dec 3, 2020 at 10:15 AM Kyotaro Horiguchi > > wrote: > > > I don't think you're missing something. As I (tried to..) mentioned in > > > another branch of this thread,

Re: Huge memory consumption on partitioned table with FKs

2020-12-02 Thread Kyotaro Horiguchi
At Thu, 3 Dec 2020 12:27:53 +0900, Amit Langote wrote in > Hello, > > On Thu, Dec 3, 2020 at 10:15 AM Kyotaro Horiguchi > wrote: > > At Wed, 2 Dec 2020 22:02:50 +0900, Amit Langote > > wrote in > > > Hmm, I don't see what the problem is here, because it's not > > > RI_ConstraintInfo that is

Re: Huge memory consumption on partitioned table with FKs

2020-12-02 Thread Amit Langote
Hello, On Thu, Dec 3, 2020 at 10:15 AM Kyotaro Horiguchi wrote: > At Wed, 2 Dec 2020 22:02:50 +0900, Amit Langote > wrote in > > Hello, > > > > On Tue, Dec 1, 2020 at 9:40 AM Kyotaro Horiguchi > > wrote: > > > > > > At Mon, 30 Nov 2020 21:03:45 -0300, Alvaro Herrera > > > wrote in > > > > On

Re: Huge memory consumption on partitioned table with FKs

2020-12-02 Thread Keisuke Kuroda
Hi Hackers, >> I would embed all this knowledge in ri_BuildQueryKey though, without >> adding the new function ri_GetParentConstOid. I don't think that >> function meaningful abstraction value, and instead it would make what I >> suggest more difficult. > It seems to me reasonable. Indeed, I tr

Re: Huge memory consumption on partitioned table with FKs

2020-12-02 Thread Kyotaro Horiguchi
At Wed, 2 Dec 2020 22:02:50 +0900, Amit Langote wrote in > Hello, > > On Tue, Dec 1, 2020 at 9:40 AM Kyotaro Horiguchi > wrote: > > > > At Mon, 30 Nov 2020 21:03:45 -0300, Alvaro Herrera > > wrote in > > > On 2020-Nov-26, Kyotaro Horiguchi wrote: > > > > > > > This shares RI_ConstraintInfo c

Re: Huge memory consumption on partitioned table with FKs

2020-12-02 Thread Simon Riggs
On Tue, 1 Dec 2020 at 00:03, Alvaro Herrera wrote: > cache entry is reused in the common case where they are identical. Does a similar situation exist for partition statistics accessed during planning? Or planning itself? It would be useful to avoid repeated access to similar statistics and repe

Re: Huge memory consumption on partitioned table with FKs

2020-12-02 Thread Amit Langote
Hello, On Tue, Dec 1, 2020 at 9:40 AM Kyotaro Horiguchi wrote: > > At Mon, 30 Nov 2020 21:03:45 -0300, Alvaro Herrera > wrote in > > On 2020-Nov-26, Kyotaro Horiguchi wrote: > > > > > This shares RI_ConstraintInfo cache by constraints that shares the > > > same parent constraints. But you forgo

Re: Huge memory consumption on partitioned table with FKs

2020-11-30 Thread Corey Huinker
On Mon, Nov 30, 2020 at 9:48 PM Tom Lane wrote: > Corey Huinker writes: > > Given that we're already looking at these checks, I was wondering if this > > might be the time to consider implementing these checks by directly > > scanning the constraint index. > > Yeah, maybe. Certainly ri_triggers

Re: Huge memory consumption on partitioned table with FKs

2020-11-30 Thread Tom Lane
Corey Huinker writes: > Given that we're already looking at these checks, I was wondering if this > might be the time to consider implementing these checks by directly > scanning the constraint index. Yeah, maybe. Certainly ri_triggers is putting a huge amount of effort into working around the S

Re: Huge memory consumption on partitioned table with FKs

2020-11-30 Thread Corey Huinker
> > I think this can be solved easily in the patch, by having > ri_BuildQueryKey() compare the parent's fk_attnums to the parent; if > they are equal then use the parent's constaint_id, otherwise use the > child constraint. That way, the cache entry is reused in the common > case where they are id

Re: Huge memory consumption on partitioned table with FKs

2020-11-30 Thread Kyotaro Horiguchi
At Mon, 30 Nov 2020 21:03:45 -0300, Alvaro Herrera wrote in > On 2020-Nov-26, Kyotaro Horiguchi wrote: > > > This shares RI_ConstraintInfo cache by constraints that shares the > > same parent constraints. But you forgot that the cache contains some > > members that can differ among partitions.

Re: Huge memory consumption on partitioned table with FKs

2020-11-30 Thread Alvaro Herrera
On 2020-Nov-26, Kyotaro Horiguchi wrote: > This shares RI_ConstraintInfo cache by constraints that shares the > same parent constraints. But you forgot that the cache contains some > members that can differ among partitions. > > Consider the case of attaching a partition that have experienced a >

Re: Huge memory consumption on partitioned table with FKs

2020-11-25 Thread Kyotaro Horiguchi
At Thu, 26 Nov 2020 09:59:28 +0900, Keisuke Kuroda wrote in > Hi Hackers, > > Analyzed the problem and created a patch to resolve it. > > # Problem 1 > > When you create a foreign key to a partitioned table, referential > integrity function is created for the number of partitions. > Internall

Re: Huge memory consumption on partitioned table with FKs

2020-11-25 Thread Keisuke Kuroda
Hi Hackers, Analyzed the problem and created a patch to resolve it. # Problem 1 When you create a foreign key to a partitioned table, referential integrity function is created for the number of partitions. Internally, SPI_prepare() creates a plan and SPI_keepplan() caches the plan. The more par

Huge memory consumption on partitioned table with FKs

2020-11-23 Thread Tatsuro Yamada
Hi Hackers, My company (NTT Comware) and NTT OSS Center did verification of partitioned table on PG14dev, and we faced a problem that consumed huge memory when we created a Foreign key constraint on a partitioned table including 500 partitioning tables and inserted some data. We investigated it