postgresql/src/include/catalog
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
..
.gitignore Put genbki.pl output into src/include/catalog/ directly 2024-03-14 07:11:21 +01:00
Makefile Put genbki.pl output into src/include/catalog/ directly 2024-03-14 07:11:21 +01:00
binary_upgrade.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
catalog.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
catversion.h Revert: Implement pg_wal_replay_wait() stored procedure 2024-04-11 17:28:15 +03:00
dependency.h Remove ObjectClass type 2024-03-26 10:08:56 +01:00
duplicate_oids Update copyright for 2024 2024-01-03 20:49:05 -05:00
genbki.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
heap.h Generalize handling of nullable pg_attribute columns in DDL 2024-03-17 12:30:51 +01:00
index.h Add attstattarget to FormExtraData_pg_attribute 2024-03-17 12:38:27 +01:00
indexing.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
meson.build Put genbki.pl output into src/include/catalog/ directly 2024-03-14 07:11:21 +01:00
namespace.h Replace BackendIds with 0-based ProcNumbers 2024-03-03 19:38:22 +02:00
objectaccess.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
objectaddress.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
partition.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_aggregate.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_aggregate.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_am.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_am.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_amop.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_amop.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_amproc.dat Add stratnum GiST support function 2024-01-19 15:42:13 +01:00
pg_amproc.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_attrdef.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_attribute.h Add attstattarget to FormExtraData_pg_attribute 2024-03-17 12:38:27 +01:00
pg_auth_members.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_authid.dat Reintroduce MAINTAIN privilege and pg_maintain predefined role. 2024-03-13 14:49:26 -05:00
pg_authid.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_cast.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_cast.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_class.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_class.h Allow specifying an access method for partitioned tables 2024-03-25 16:30:36 +01:00
pg_collation.dat Use version for builtin collations. 2024-03-29 10:53:26 -07:00
pg_collation.h Introduce "builtin" collation provider. 2024-03-13 23:33:44 -07:00
pg_constraint.h Fix restore of not-null constraints with inheritance 2024-04-18 15:35:15 +02:00
pg_control.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_conversion.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_conversion.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_database.dat Catalog changes preparing for builtin collation provider. 2024-03-09 14:48:18 -08:00
pg_database.h Catalog changes preparing for builtin collation provider. 2024-03-09 14:48:18 -08:00
pg_db_role_setting.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_default_acl.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_depend.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_description.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_enum.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_event_trigger.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_extension.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_foreign_data_wrapper.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_foreign_server.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_foreign_table.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_index.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_inherits.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_init_privs.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_language.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_language.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_largeobject.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_largeobject_metadata.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_namespace.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_namespace.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_opclass.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_opclass.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_operator.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_operator.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_opfamily.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_opfamily.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_parameter_acl.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_partitioned_table.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_policy.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_proc.dat Revert: Implement pg_wal_replay_wait() stored procedure 2024-04-11 17:28:15 +03:00
pg_proc.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_publication.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_publication_namespace.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_publication_rel.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_range.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_range.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_replication_origin.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_rewrite.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_seclabel.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_sequence.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_shdepend.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_shdescription.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_shseclabel.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_statistic.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_statistic_ext.h Make stxstattarget nullable 2024-03-17 12:26:26 +01:00
pg_statistic_ext_data.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_subscription.h Add a failover option to subscriptions. 2024-01-30 16:49:28 +05:30
pg_subscription_rel.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_tablespace.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_tablespace.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_transform.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_trigger.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_ts_config.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_ts_config.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_ts_config_map.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_ts_config_map.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_ts_dict.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_ts_dict.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_ts_parser.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_ts_parser.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_ts_template.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_ts_template.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
pg_type.dat Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_type.h Revert "Improve compression and storage support with inheritance" 2024-02-20 11:10:59 +01:00
pg_user_mapping.h Generate syscache info from catalog files 2024-01-23 07:31:06 +01:00
reformat_dat_file.pl Update copyright for 2024 2024-01-03 20:49:05 -05:00
renumber_oids.pl Update copyright for 2024 2024-01-03 20:49:05 -05:00
storage.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
storage_xlog.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
toasting.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
unused_oids Update copyright for 2024 2024-01-03 20:49:05 -05:00