postgresql/src
Tom Lane c9f7f92648 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
..
backend Allow REPLICA IDENTITY to be set on an index that's not (yet) valid. 2023-01-21 13:10:29 -05:00
bin Zero initialize uses of instr_time about to trigger compiler warnings 2023-01-20 21:16:47 -08:00
common Use appendStringInfoSpaces in more places 2023-01-20 13:07:24 +13:00
fe_utils Refactor code for restoring files via shell commands 2023-01-18 11:15:48 +09:00
include instr_time: Represent time as an int64 on all platforms 2023-01-20 21:16:47 -08:00
interfaces Update copyright for 2023 2023-01-02 15:00:37 -05:00
makefiles Update copyright for 2023 2023-01-02 15:00:37 -05:00
pl New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00
port Update copyright for 2023 2023-01-02 15:00:37 -05:00
template Use unnamed POSIX semaphores on Cygwin. 2023-01-06 10:33:28 +13:00
test Allow REPLICA IDENTITY to be set on an index that's not (yet) valid. 2023-01-21 13:10:29 -05:00
timezone Update copyright for 2023 2023-01-02 15:00:37 -05:00
tools Remove SHM_QUEUE 2023-01-19 18:55:51 -08:00
tutorial Update copyright for 2023 2023-01-02 15:00:37 -05:00
.gitignore
DEVELOPERS
Makefile
Makefile.global.in autoconf: Move export_dynamic determination to configure 2022-12-06 18:55:28 -08:00
Makefile.shlib autoconf: Rely on ar supporting index creation 2022-10-07 11:53:39 -07:00
meson.build Update copyright for 2023 2023-01-02 15:00:37 -05:00
nls-global.mk Fix for make unportability 2022-07-13 09:15:01 +02:00