| From: | Ante Krešić <ante(at)tigerdata(dot)com> |
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | [PATCH] REPLICA IDENTITY USING INDEX accepts column with invalid NOT NULL |
| Date: | 2026-05-14 13:06:56 |
| Message-ID: | CABXQ4dJUibZzN91qvWmsfA7MUDn9YRCNyu3CcukdyokbH1=41Q@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
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,
Ante Kresic
Staff Engineer | Tiger Data
TigerData.com
| Attachment | Content-Type | Size |
|---|---|---|
| 0001-Reject-REPLICA-IDENTITY-USING-INDEX-on-column-with-i.patch | text/x-patch | 6.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Tatsuo Ishii | 2026-05-14 12:56:22 | Re: Should IGNORE NULLS cache nullness for volatile arguments? |