Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-11-04 Thread Jehan-Guillaume de Rorthais
On Thu, 3 Nov 2022 20:44:16 +0100 Alvaro Herrera wrote: > On 2022-Oct-05, Alvaro Herrera wrote: > > > I've been giving the patches a look and it caused me to notice two > > additional bugs in the same area: > > > > - FKs in partitions are sometimes marked NOT VALID. This is because of > >

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-11-03 Thread Alvaro Herrera
On 2022-Oct-05, Alvaro Herrera wrote: > I've been giving the patches a look and it caused me to notice two > additional bugs in the same area: > > - FKs in partitions are sometimes marked NOT VALID. This is because of > missing initialization when faking up a Constraint node in >

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-10-07 Thread Alvaro Herrera
On 2022-Oct-05, Alvaro Herrera wrote: > Backpatching this to 12 shows yet another problem -- the topmost > relation acquires additional FK constraints, not yet sure why. I think > we must have fixed something in 13 that wasn't backpatched, but I can't > remember what it is and whether it was

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-10-05 Thread Alvaro Herrera
Backpatching this to 12 shows yet another problem -- the topmost relation acquires additional FK constraints, not yet sure why. I think we must have fixed something in 13 that wasn't backpatched, but I can't remember what it is and whether it was intentionally not backpatched. Looking ... --

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-10-05 Thread Alvaro Herrera
On 2022-Oct-03, Jehan-Guillaume de Rorthais wrote: > Thank you! This is fixed and rebased on current master branch in patches > attached. Thanks. As far as I can see this fixes the bugs that were reported. I've been giving the patches a look and it caused me to notice two additional bugs in the

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-10-03 Thread Jehan-Guillaume de Rorthais
On Fri, 30 Sep 2022 16:11:09 -0700 Zhihong Yu wrote: > On Fri, Sep 30, 2022 at 3:30 PM Jehan-Guillaume de Rorthais > wrote: ... > > +* Self-Foreign keys are ignored as the index was preliminary > created > > preliminary created -> primarily created Thank you! This is fixed and

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-09-30 Thread Zhihong Yu
On Fri, Sep 30, 2022 at 3:30 PM Jehan-Guillaume de Rorthais wrote: > Hi, > > Please, find in attachment a small serie of patch: > > 0001 fix the constraint parenting bug. Not much to say. It's basically > your > patch we discussed with some more comments and the check on contype > equals to

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-09-30 Thread Jehan-Guillaume de Rorthais
Hi, Please, find in attachment a small serie of patch: 0001 fix the constraint parenting bug. Not much to say. It's basically your patch we discussed with some more comments and the check on contype equals to either primary, unique or exclusion. 0002 fix the self-FK being cloned twice

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-08-24 Thread Alvaro Herrera
On 2022-Aug-24, Jehan-Guillaume de Rorthais wrote: > I was naively wondering about such a patch, but was worrying about potential > side effects on ATExecAttachPartitionIdx(), DetachPartitionFinalize() and > DefineIndex() where I didn't had a single glance. Did you had a look? No. But AFAIR all

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-08-24 Thread Jehan-Guillaume de Rorthais
On Tue, 23 Aug 2022 18:30:06 +0200 Alvaro Herrera wrote: > On 2022-Aug-23, Jehan-Guillaume de Rorthais wrote: > > Hi, > > [...] > > > However, it seems get_relation_idx_constraint_oid(), introduced in > > eb7ed3f3063, assume there could be only ONE constraint depending to an > > index. But in

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-08-23 Thread Tom Lane
Alvaro Herrera writes: > If this is OK, we should make this API quirkiness very explicit in the > comments, so the patch needs to be a few lines larger in order to be > committable. Also, perhaps the check should be that contype equals > either primary or unique, rather than it doesn't equal

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-08-23 Thread Alvaro Herrera
On 2022-Aug-23, Zhihong Yu wrote: > A bigger question I have, even with the additional filtering, is what if > there are multiple constraints ? > How do we decide which unique / primary key constraint to return ? > > Looks like there is no known SQL statements leading to such state, but > should

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-08-23 Thread Zhihong Yu
On Tue, Aug 23, 2022 at 9:47 AM Alvaro Herrera wrote: > On 2022-Aug-23, Zhihong Yu wrote: > > > I was thinking of the following patch. > > Basically, if there is only one matching constraint. we still return it. > > > > diff --git a/src/postgres/src/backend/catalog/pg_constraint.c > >

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-08-23 Thread Alvaro Herrera
On 2022-Aug-23, Zhihong Yu wrote: > I was thinking of the following patch. > Basically, if there is only one matching constraint. we still return it. > > diff --git a/src/postgres/src/backend/catalog/pg_constraint.c > b/src/postgres/src/backend/catalog/pg_constraint.c > index

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-08-23 Thread Zhihong Yu
On Tue, Aug 23, 2022 at 9:30 AM Alvaro Herrera wrote: > On 2022-Aug-23, Jehan-Guillaume de Rorthais wrote: > > Hi, > > [...] > > > However, it seems get_relation_idx_constraint_oid(), introduced in > eb7ed3f3063, > > assume there could be only ONE constraint depending to an index. But in > fact,

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-08-23 Thread Alvaro Herrera
On 2022-Aug-23, Jehan-Guillaume de Rorthais wrote: Hi, [...] > However, it seems get_relation_idx_constraint_oid(), introduced in > eb7ed3f3063, > assume there could be only ONE constraint depending to an index. But in fact, > multiple constraints can rely on the same index, eg.: the PK and a

Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition)

2022-08-23 Thread Zhihong Yu
On Tue, Aug 23, 2022 at 8:07 AM Jehan-Guillaume de Rorthais wrote: > Hi all, > > I've been able to work on this issue and isolate where in the code the > oddity > is laying. > > During ATExecAttachPartition(), AttachPartitionEnsureIndexes() look for > existing > required index on the partition