BUG #19846: dump/restore marks inherited NOT VALID not-null constraint as local

Started by PG Bug reporting form21 days ago1 messagesbugs

Thread notes

1 note#bug
hackorum-bot#bug
hackorum-bot
2 days ago

@global #bug

#bug
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following bug has been logged on the website:

Bug reference: 19846
Logged by: Atish Prakash
Email address: 125atishprak@gmail.com
PostgreSQL version: 18.6
Operating system: Linux x86_64
Description:

A child's not-null constraint inherited from a NOT VALID parent constraint
comes
back with conislocal = true after a dump and restore. The child then behaves
differently when the parent's constraint is dropped.

CREATE TABLE np(a int, b int);
ALTER TABLE np ADD CONSTRAINT nb NOT NULL b NOT VALID;
CREATE TABLE nc() INHERITS (np);

SELECT conislocal FROM pg_constraint
WHERE conrelid = 'nc'::regclass AND conname = 'nb';
-- original: f restored: t

ALTER TABLE np DROP CONSTRAINT nb;
SELECT attnotnull FROM pg_attribute
WHERE attrelid = 'nc'::regclass AND attname = 'b';
-- original: f restored: t

Expected: the same result before and after the restore. A child of a valid
not-null constraint does not show the difference in conislocal. Partitions
are
also affected: a partition of a table with a NOT VALID not-null constraint
comes
back with conislocal = true in the same way.

pg_upgrade from 19rc1 to master changes conislocal in the same way.

I have not written a patch or traced the exact statements responsible.

Found with dump and restore differential tests. I reproduced and checked the
result myself.