RE: [BUG]Missing REPLICA IDENTITY check when DROP NOT NULL

From: "tanghy(dot)fnst(at)fujitsu(dot)com" <tanghy(dot)fnst(at)fujitsu(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, "houzj(dot)fnst(at)fujitsu(dot)com" <houzj(dot)fnst(at)fujitsu(dot)com>
Subject: RE: [BUG]Missing REPLICA IDENTITY check when DROP NOT NULL
Date: 2021-11-25 02:51:24
Message-ID: OS0PR01MB61130903335500FCA7EBD2BDFB629@OS0PR01MB6113.jpnprd01.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Nov 24, 2021 7:29 PM, Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> On Wed, Nov 24, 2021 at 07:04:51AM +0000, tanghy(dot)fnst(at)fujitsu(dot)com wrote:
> > create table tbl (a int not null unique);
> > alter table tbl replica identity using INDEX tbl_a_key;
> > alter table tbl alter column a drop not null;
> > insert into tbl values (null);
>
> Oops. Yes, that's obviously not good.
>
> > To solve the above problem, I think it's better to add a check when
> > executing ALTER COLUMN DROP NOT NULL,
> > and report an error if this column is part of replica identity.
>
> I'd say that you are right to block the operation. I'll try to play a
> bit with this stuff tomorrow.
>
> > Attaching a patch that disallow DROP NOT NULL on a column if it's in
> > a REPLICA IDENTITY index. Also added a test in it.
>
> if (indexStruct->indkey.values[i] == attnum)
> ereport(ERROR,
> (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
> - errmsg("column \"%s\" is in a primary key",
> + errmsg(ngettext("column \"%s\" is in a primary key",
> + "column \"%s\" is in a REPLICA IDENTITY index",
> + indexStruct->indisprimary),
> colName)));
> Using ngettext() looks incorrect to me here as it is used to get the
> plural form of a string, so you'd better make these completely
> separated instead.

Thanks for your comment. I agree with you.
I have fixed it and attached v2 patch.

Regards,
Tang

Attachment Content-Type Size
v2-0001-Disallow-DROP-NOT-NULL-on-a-column-in-the-REPLICA.patch application/octet-stream 3.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2021-11-25 03:22:03 Re: row filtering for logical replication
Previous Message houzj.fnst@fujitsu.com 2021-11-25 01:57:01 RE: pg_get_publication_tables() output duplicate relid