postgresql/src/backend/catalog
Tom Lane 9e4288ce6d Allow REPLICA IDENTITY to be set on an index that's not (yet) valid.
The motivation for this change is that when pg_dump dumps a
partitioned index that's marked REPLICA IDENTITY, it generates a
command sequence that applies REPLICA IDENTITY before the partitioned
index has been marked valid, causing restore to fail.  We could
perhaps change pg_dump to not do it like that, but that would be
difficult and would not fix existing dump files with the problem.
There seems to be very little reason for the backend to disallow
this anyway --- the code ignores indisreplident when the index
isn't valid --- so instead let's fix it by allowing the case.

Commit 9511fb37a previously expressed a concern that allowing
indisreplident to be set on invalid indexes might allow us to
wind up in a situation where a table could have indisreplident
set on multiple indexes.  I'm not sure I follow that concern
exactly, but in any case the only way that could happen is because
relation_mark_replica_identity is too trusting about the existing set
of markings being valid.  Let's just rip out its early-exit code path
(which sure looks like premature optimization anyway; what are we
doing expending code to make redundant ALTER TABLE ... REPLICA
IDENTITY commands marginally faster and not-redundant ones marginally
slower?) and fix it to positively guarantee that no more than one
index is marked indisreplident.

The pg_dump failure can be demonstrated in all supported branches,
so back-patch all the way.  I chose to back-patch 9511fb37a as well,
just to keep indisreplident handling the same in all branches.

Per bug #17756 from Sergey Belyashov.

Discussion: https://postgr.es/m/17756-dd50e8e0c8dd4a40@postgresql.org
2023-01-21 13:10:29 -05:00
..
.gitignore Build in some knowledge about foreign-key relationships in the catalogs. 2021-02-02 17:11:55 -05:00
Catalog.pm Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
Makefile Allow granting SET and ALTER SYSTEM privileges on GUC parameters. 2022-04-06 13:24:33 -04:00
aclchk.c Fix come incorrect elog() messages in aclchk.c 2022-12-23 10:04:30 +09:00
catalog.c Rethink method for assigning OIDs to the template0 and postgres DBs. 2022-04-21 16:23:15 -04:00
dependency.c Change some errdetail() to errdetail_internal() 2022-09-28 17:14:53 +02:00
genbki.pl Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
heap.c pgstat: Fix transactional stats dropping for indexes 2022-09-23 13:13:50 -07:00
index.c Allow REPLICA IDENTITY to be set on an index that's not (yet) valid. 2023-01-21 13:10:29 -05:00
indexing.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
information_schema.sql Fix bogus dependency handling for GENERATED expressions. 2022-03-21 14:58:49 -04:00
namespace.c Fix temporary object cleanup failing due to toast access without snapshot. 2022-02-21 08:57:34 -08:00
objectaccess.c Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
objectaddress.c Tighten pg_get_object_address argument checking 2022-09-21 09:42:22 -04:00
partition.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
pg_aggregate.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
pg_attrdef.c Remove extraneous blank lines before block-closing braces 2022-04-13 19:16:02 +02:00
pg_cast.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
pg_class.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
pg_collation.c In extensions, don't replace objects not belonging to the extension. 2022-08-08 11:12:31 -04:00
pg_constraint.c Fix self-referencing foreign keys with partitioned tables 2022-10-07 19:37:48 +02:00
pg_conversion.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
pg_db_role_setting.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
pg_depend.c In extensions, don't replace objects not belonging to the extension. 2022-08-08 11:12:31 -04:00
pg_enum.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
pg_inherits.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
pg_largeobject.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
pg_namespace.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
pg_operator.c In extensions, don't replace objects not belonging to the extension. 2022-08-08 11:12:31 -04:00
pg_parameter_acl.c Allow granting SET and ALTER SYSTEM privileges on GUC parameters. 2022-04-06 13:24:33 -04:00
pg_proc.c Avoid crash after function syntax error in a replication worker. 2022-11-03 12:01:57 -04:00
pg_publication.c Message style improvements 2022-09-24 18:38:35 -04:00
pg_range.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
pg_shdepend.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
pg_subscription.c Reorder subskiplsn in pg_subscription to avoid alignment issues. 2022-04-07 09:39:25 +05:30
pg_type.c In extensions, don't replace objects not belonging to the extension. 2022-08-08 11:12:31 -04:00
sql_feature_packages.txt Cleanup in SQL features files 2020-03-28 08:46:18 +01:00
sql_features.txt Revert SQL/JSON features 2022-09-01 17:10:42 -04:00
storage.c Add 'static' to file-local variables missing it. 2022-05-12 12:39:33 -07:00
system_functions.sql pgstat: add pg_stat_have_stats() test helper. 2022-04-07 00:21:54 -07:00
system_views.sql Fix new pg_publication_tables query. 2022-09-06 18:00:32 -04:00
toasting.c Add UNIQUE null treatment option 2022-02-03 11:48:21 +01:00