postgresql/src/test/regress
Alvaro Herrera d9f686a72e
Fix restore of not-null constraints with inheritance
In tables with primary keys, pg_dump creates tables with primary keys by
initially dumping them with throw-away not-null constraints (marked "no
inherit" so that they don't create problems elsewhere), to later drop
them once the primary key is restored.  Because of a unrelated
consideration, on tables with children we add not-null constraints to
all columns of the primary key when it is created.

If both a table and its child have primary keys, and pg_dump happens to
emit the child table first (and its throw-away not-null) and later its
parent table, the creation of the parent's PK will fail because the
throw-away not-null constraint collides with the permanent not-null
constraint that the PK wants to add, so the dump fails to restore.

We can work around this problem by letting the primary key "take over"
the child's not-null.  This requires no changes to pg_dump, just two
changes to ALTER TABLE: first, the ability to convert a no-inherit
not-null constraint into a regular inheritable one (including recursing
down to children, if there are any); second, the ability to "drop" a
constraint that is defined both directly in the table and inherited from
a parent (which simply means to mark it as no longer having a local
definition).

Secondarily, change ATPrepAddPrimaryKey() to acquire locks all the way
down the inheritance hierarchy, in case we need to recurse when
propagating constraints.

These two changes allow pg_dump to reproduce more cases involving
inheritance from versions 16 and older.

Lastly, make two changes to pg_dump: 1) do not try to drop a not-null
constraint that's marked as inherited; this allows a dump to restore
with no errors if a table with a PK inherits from another which also has
a PK; 2) avoid giving inherited constraints throwaway names, for the
rare cases where such a constraint survives after the restore.

Reported-by: Andrew Bille <andrewbille@gmail.com>
Reported-by: Justin Pryzby <pryzby@telsasoft.com>
Discussion: https://postgr.es/m/CAJnzarwkfRu76_yi3dqVF_WL-MpvT54zMwAxFwJceXdHB76bOA@mail.gmail.com
Discussion: https://postgr.es/m/Zh0aAH7tbZb-9HbC@pryzbyj2023
2024-04-18 15:35:15 +02:00
..
data Fix full text search to handle NOT above a phrase search correctly. 2020-04-27 12:21:04 -04:00
expected Fix restore of not-null constraints with inheritance 2024-04-18 15:35:15 +02:00
sql Fix restore of not-null constraints with inheritance 2024-04-18 15:35:15 +02:00
.gitignore Fix inconsistencies and typos in the tree, take 10 2019-08-13 13:53:41 +09:00
GNUmakefile Update copyright for 2024 2024-01-03 20:49:05 -05:00
Makefile Remove AIX support 2024-02-28 15:17:23 +04:00
README
meson.build Update copyright for 2024 2024-01-03 20:49:05 -05:00
parallel_schedule Implement ALTER TABLE ... SPLIT PARTITION ... command 2024-04-07 01:18:44 +03:00
pg_regress.c pg_regress: Save errno in emit_tap_output_v() and switch to %m 2024-04-04 11:33:07 +09:00
pg_regress.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_regress_main.c Fix handling of expecteddir in pg_regress 2024-03-15 17:02:07 +01:00
regress.c Mop-up for AIX-ectomy: remove now-dead test code. 2024-02-28 14:34:19 -05:00
regressplans.sh Fix inconsistencies in the code 2019-07-08 13:15:09 +09:00
resultmap Remove HP-UX port. 2022-07-08 14:05:05 +12:00

README

Documentation concerning how to run these regression tests and interpret
the results can be found in the PostgreSQL manual, in the chapter
"Regression Tests".