Re: [PATCH] REPLICA IDENTITY USING INDEX accepts column with invalid NOT NULL

From: Aleksander Alekseev <aleksander(at)tigerdata(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: Ante Krešić <ante(at)tigerdata(dot)com>
Subject: Re: [PATCH] REPLICA IDENTITY USING INDEX accepts column with invalid NOT NULL
Date: 2026-05-26 09:35:41
Message-ID: CAJ7c6TN9GHo3D4dV5NYhM5vCd00Hy1XpCRC_oz8G-mTZ1jwg8A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Ante,

> ALTER TABLE ... REPLICA IDENTITY USING INDEX checks key columns by
> reading attnotnull, but since a379061a22a8 (PG 18, NOT NULL NOT VALID)
> attnotnull is set even when the constraint is unvalidated. An index on
> a column that actually contains NULLs is therefore accepted as replica
> identity:
>
> CREATE TABLE t (id int);
> INSERT INTO t VALUES (1), (NULL), (2);
> ALTER TABLE t ADD CONSTRAINT id_nn NOT NULL id NOT VALID;
> CREATE UNIQUE INDEX t_idx ON t(id);
> ALTER TABLE t REPLICA IDENTITY USING INDEX t_idx; -- accepted
> -- relreplident => 'i'
>
> This would cause data divergence on UPDATE/DELETE targeting NULL-keyed rows.
>
> Patch follows same pattern as d9ffc27291f (the same bugfix for identity columns);
> after the attnotnull check, look up the constraint and reject if !convalidated.

Thanks for the patch. This clearly seems to be a bug.

The patch is well written and has regression tests. The tests pass, I
also tested under Valgrind. All in all the patch looks good to me.

I added the patch to the commitfest application to make sure it's not
going to be lost [1]. Please add yourself as the author.

[1]: https://commitfest.postgresql.org/patch/6801/

--
Best regards,
Aleksander Alekseev

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message shveta malik 2026-05-26 09:38:19 Re: Proposal: Conflict log history table for Logical Replication
Previous Message Aleksander Alekseev 2026-05-26 09:16:50 Re: [PATCH] Little refactoring of portalcmds.c