Admit deferrable PKs into rd_pkindex, but flag them as such
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 8 Mar 2024 15:32:29 +0000 (16:32 +0100)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Fri, 8 Mar 2024 15:32:29 +0000 (16:32 +0100)
commit270af6f0df764d326e1a7355f4ce10dc73b05dac
tree2ef0efd75bf20275c947c8078ec67ad3d296cd38
parent4c1973fcaecd9ef11de14ac55d3ec1432f6b82dc
Admit deferrable PKs into rd_pkindex, but flag them as such

... and in particular don't return them as replica identity.

The motivation for this change is letting the primary keys be seen by
code that derives NOT NULL constraints from them, when creating
inheritance children; before this change, if you had a deferrable PK,
pg_dump would not recreate the attnotnull marking properly, because the
column would not be considered as having anything to back said marking
after dropping the throwaway NOT NULL constraint.

The reason we don't want these PKs as replica identities is that
replication can corrupt data, if the uniqueness constraint is
transiently broken.

Reported-by: Amul Sul <sulamul@gmail.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Discussion: http://postgr.es/m/CAAJ_b94QonkgsbDXofakHDnORQNgafd1y3Oa5QXfpQNJyXyQ7A@mail.gmail.com
src/backend/replication/logical/relation.c
src/backend/utils/cache/relcache.c
src/include/utils/rel.h
src/test/regress/expected/constraints.out
src/test/regress/expected/publication.out
src/test/regress/expected/replica_identity.out
src/test/regress/sql/constraints.sql
src/test/regress/sql/publication.sql
src/test/regress/sql/replica_identity.sql