postgresql/src/backend/catalog
Álvaro Herrera 11ff192b5b
Elide not-null constraint checks on child tables during PK creation
We were unnecessarily acquiring AccessExclusiveLock on all child tables
when "ALTER TABLE ONLY sometab ADD PRIMARY KEY" was run on their parent
table, an oversight in commit 14e87ffa5c.  This caused deadlocks
during pg_restore of partitioned tables.

The reason to acquire the AEL was that we need to verify that child
tables have the involved columns already marked as not-null; but if the
parent table has an inheritable not-null constraint, then all children
must necessarily be in the correct state already, so we can skip the
check, which avoids acquiring the lock.  Reorder the code so that it
works that way.  This doesn't change things in the case where the
constraint doesn't exist, but that case is of lesser importance because
it doesn't occur during parallel pg_restore.

While at it, reword some errmsg() and add errhint() to similar cases in
related but not adjacent code.

Diagnosed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Tender Wang <tndrwang@gmail.com>
Discussion: https://postgr.es/m/67469c1c-38bc-7d94-918a-67033f5dd731@gmx.net
Discussion: https://postgr.es/m/2045026.1743801143@sss.pgh.pa.us
Discussion: https://postgr.es/m/1280408.1744650810@sss.pgh.pa.us
2025-04-16 21:51:23 +02:00
..
aclchk.c Extend ALTER DEFAULT PRIVILEGES to define default privileges for large objects. 2025-04-04 19:02:17 +09:00
catalog.c Use PRI?64 instead of "ll?" in format strings (continued). 2025-03-29 10:43:57 +01:00
Catalog.pm Update copyright for 2025 2025-01-01 11:21:55 -05:00
dependency.c Disallow NAMEDTUPLESTORE RTEs in stored views, rules, etc. 2025-01-08 16:35:54 -05:00
genbki.pl Label the contents of pg_*_d.h files a little better. 2025-03-21 15:09:46 -04:00
heap.c Allow NOT NULL constraints to be added as NOT VALID 2025-04-07 19:19:50 +02:00
index.c CREATE INDEX: do update index stats if autovacuum=off. 2025-03-10 17:49:27 -04:00
indexing.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
information_schema.sql Add support for NOT ENFORCED in CHECK constraints 2025-01-11 10:52:30 +01:00
Makefile Update copyright for 2025 2025-01-01 11:21:55 -05:00
meson.build Update copyright for 2025 2025-01-01 11:21:55 -05:00
namespace.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
objectaccess.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
objectaddress.c Extend ALTER DEFAULT PRIVILEGES to define default privileges for large objects. 2025-04-04 19:02:17 +09:00
partition.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
pg_aggregate.c Fix erroneous construction of functions' dependencies on transforms. 2025-04-07 13:31:37 -04:00
pg_attrdef.c Simplify some logic around setting pg_attribute.atthasdef. 2025-03-03 13:35:48 -05:00
pg_cast.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
pg_class.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
pg_collation.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
pg_constraint.c Elide not-null constraint checks on child tables during PK creation 2025-04-16 21:51:23 +02:00
pg_conversion.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
pg_db_role_setting.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
pg_depend.c Fix an assortment of spelling mistakes and typos 2025-01-02 12:42:01 +13:00
pg_enum.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
pg_inherits.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
pg_largeobject.c Re-pgindent pg_largeobject.c after commit 0d6c477664. 2025-04-04 09:38:22 -05:00
pg_namespace.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
pg_operator.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
pg_parameter_acl.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
pg_proc.c Fix erroneous construction of functions' dependencies on transforms. 2025-04-07 13:31:37 -04:00
pg_publication.c Virtual generated columns 2025-02-07 09:46:59 +01:00
pg_range.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
pg_shdepend.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
pg_subscription.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
pg_type.c Update copyright for 2025 2025-01-01 11:21:55 -05:00
sql_feature_packages.txt Update SQL features 2023-05-02 10:59:21 +02:00
sql_features.txt Add support for NOT ENFORCED in foreign key constraints 2025-04-02 13:36:44 +02:00
storage.c Let caller of PageIsVerified() control ignore_checksum_failure 2025-03-30 16:27:10 -04:00
system_functions.sql Allow json{b}_strip_nulls to remove null array elements 2025-03-05 10:04:02 -05:00
system_views.sql Add function to get memory context stats for processes 2025-04-08 11:06:56 +02:00
toasting.c Update copyright for 2025 2025-01-01 11:21:55 -05:00