pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Reject enforcing a parent CHECK constraint over a NOT VALID chil 2+ messages / 1 participants [nested] [flat]
* pgsql: Reject enforcing a parent CHECK constraint over a NOT VALID chil @ 2026-11-01 15:50 Andrew Dunstan <andrew@dunslane.net> 0 siblings, 0 replies; 2+ messages in thread From: Andrew Dunstan @ 2026-11-01 15:50 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Reject enforcing a parent CHECK constraint over a NOT VALID child ALTER TABLE ... ALTER CONSTRAINT ... ENFORCED on a parent's NOT ENFORCED CHECK constraint marked the parent's constraint validated, but when it recursed to a child whose matching constraint was already ENFORCED and NOT VALID, it left that child alone, since its enforceability was unchanged. The child's existing rows were therefore never checked, and the parent ended up validated with a child that was not. Constraint exclusion could then skip the child when querying the parent, and so miss rows that violate the constraint. Fix by raising the same error that ALTER TABLE ... INHERIT already raises when a child has a NOT VALID copy of a parent's constraint, with a hint to validate the child's constraint first. Validating the child implicitly instead was considered, but ALTER CONSTRAINT ... ENFORCED does not validate an ENFORCED NOT VALID constraint when run directly against the table that has it, so doing so only when reached through a parent would be inconsistent. Add regression tests for both regular inheritance and partitioning. Bug introduced in 342051d73b3. Reported-by: Shihao Zhong <zhong950419@gmail.com> Author: Shihao Zhong <zhong950419@gmail.com> Author: Jian He <jian.universality@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Andrew Dunstan <andrew@dunslane.net> Discussion: https://postgr.es/m/CAGRkXqSGE=fQrjCoNQsyiCZRKfQ4SrB015CAR=3pXYB5tB=ieg@mail.gmail.com Backpatch-through: 19 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/0b12a5a7435a3b50cccea85347d9e3cf8128d88a Modified Files -------------- src/backend/commands/tablecmds.c | 15 +++++++++++++++ src/test/regress/expected/constraints.out | 11 +++++++++++ src/test/regress/expected/inherit.out | 22 ++++++++++++++++++++++ src/test/regress/sql/constraints.sql | 11 +++++++++++ src/test/regress/sql/inherit.sql | 14 ++++++++++++++ 5 files changed, 73 insertions(+) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: Reject enforcing a parent CHECK constraint over a NOT VALID chil @ 2026-11-01 15:50 Andrew Dunstan <andrew@dunslane.net> 0 siblings, 0 replies; 2+ messages in thread From: Andrew Dunstan @ 2026-11-01 15:50 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Reject enforcing a parent CHECK constraint over a NOT VALID child ALTER TABLE ... ALTER CONSTRAINT ... ENFORCED on a parent's NOT ENFORCED CHECK constraint marked the parent's constraint validated, but when it recursed to a child whose matching constraint was already ENFORCED and NOT VALID, it left that child alone, since its enforceability was unchanged. The child's existing rows were therefore never checked, and the parent ended up validated with a child that was not. Constraint exclusion could then skip the child when querying the parent, and so miss rows that violate the constraint. Fix by raising the same error that ALTER TABLE ... INHERIT already raises when a child has a NOT VALID copy of a parent's constraint, with a hint to validate the child's constraint first. Validating the child implicitly instead was considered, but ALTER CONSTRAINT ... ENFORCED does not validate an ENFORCED NOT VALID constraint when run directly against the table that has it, so doing so only when reached through a parent would be inconsistent. Add regression tests for both regular inheritance and partitioning. Bug introduced in 342051d73b3. Reported-by: Shihao Zhong <zhong950419@gmail.com> Author: Shihao Zhong <zhong950419@gmail.com> Author: Jian He <jian.universality@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Andrew Dunstan <andrew@dunslane.net> Discussion: https://postgr.es/m/CAGRkXqSGE=fQrjCoNQsyiCZRKfQ4SrB015CAR=3pXYB5tB=ieg@mail.gmail.com Backpatch-through: 19 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/8356d8e4dba6dc36c84d4a3f15f10b9c89c2cd83 Modified Files -------------- src/backend/commands/tablecmds.c | 15 +++++++++++++++ src/test/regress/expected/constraints.out | 11 +++++++++++ src/test/regress/expected/inherit.out | 22 ++++++++++++++++++++++ src/test/regress/sql/constraints.sql | 11 +++++++++++ src/test/regress/sql/inherit.sql | 14 ++++++++++++++ 5 files changed, 73 insertions(+) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-11-01 15:50 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-11-01 15:50 pgsql: Reject enforcing a parent CHECK constraint over a NOT VALID chil Andrew Dunstan <andrew@dunslane.net> 2026-11-01 15:50 pgsql: Reject enforcing a parent CHECK constraint over a NOT VALID chil Andrew Dunstan <andrew@dunslane.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox