pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Have ALTER CONSTRAINT recurse on partitioned tables
4+ messages / 1 participants
[nested] [flat]

* pgsql: Have ALTER CONSTRAINT recurse on partitioned tables
@ 2021-05-05 16:23  Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 0 replies; 4+ messages in thread

From: Alvaro Herrera @ 2021-05-05 16:23 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Have ALTER CONSTRAINT recurse on partitioned tables

When ALTER TABLE .. ALTER CONSTRAINT changes deferrability properties
changed in a partitioned table, we failed to propagate those changes
correctly to partitions and to triggers.  Repair by adding a recursion
mechanism to affect all derived constraints and all derived triggers.
(In particular, recurse to partitions even if their respective parents
are already in the desired state: it is possible for the partitions to
have been altered individually.)  Because foreign keys involve tables in
two sides, we cannot use the standard ALTER TABLE recursion mechanism,
so we invent our own by following pg_constraint.conparentid down.

When ALTER TABLE .. ALTER CONSTRAINT is invoked on the derived
pg_constraint object that's automaticaly created in a partition as a
result of a constraint added to its parent, raise an error instead of
pretending to work and then failing to modify all the affected triggers.
Before this commit such a command would be allowed but failed to affect
all triggers, so it would silently misbehave.  (Restoring dumps of
existing databases is not affected, because pg_dump does not produce
anything for such a derived constraint anyway.)

Add some tests for the case.

Backpatch to 11, where foreign key support was added to partitioned
tables by commit 3de241dba86f.  (A related change is commit f56f8f8da6af
in pg12 which added support for FKs *referencing* partitioned tables;
this is what forces us to use an ad-hoc recursion mechanism for this.)

Diagnosed by Tom Lane from bug report from Ron L Johnson.  As of this
writing, no reviews were offered.

Discussion: https://postgr.es/m/75fe0761-a291-86a9-c8d8-4906da077469@gmail.com
Discussion: https://postgr.es/m/3144850.1607369633@sss.pgh.pa.us

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/923c13520f1b01a5563ec272de5a0a59b343f892

Modified Files
--------------
src/backend/commands/tablecmds.c          | 196 ++++++++++++++++++++++++------
src/test/regress/expected/foreign_key.out |  78 ++++++++++++
src/test/regress/sql/foreign_key.sql      |  75 ++++++++++++
3 files changed, 311 insertions(+), 38 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Have ALTER CONSTRAINT recurse on partitioned tables
@ 2021-05-05 16:23  Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 0 replies; 4+ messages in thread

From: Alvaro Herrera @ 2021-05-05 16:23 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Have ALTER CONSTRAINT recurse on partitioned tables

When ALTER TABLE .. ALTER CONSTRAINT changes deferrability properties
changed in a partitioned table, we failed to propagate those changes
correctly to partitions and to triggers.  Repair by adding a recursion
mechanism to affect all derived constraints and all derived triggers.
(In particular, recurse to partitions even if their respective parents
are already in the desired state: it is possible for the partitions to
have been altered individually.)  Because foreign keys involve tables in
two sides, we cannot use the standard ALTER TABLE recursion mechanism,
so we invent our own by following pg_constraint.conparentid down.

When ALTER TABLE .. ALTER CONSTRAINT is invoked on the derived
pg_constraint object that's automaticaly created in a partition as a
result of a constraint added to its parent, raise an error instead of
pretending to work and then failing to modify all the affected triggers.
Before this commit such a command would be allowed but failed to affect
all triggers, so it would silently misbehave.  (Restoring dumps of
existing databases is not affected, because pg_dump does not produce
anything for such a derived constraint anyway.)

Add some tests for the case.

Backpatch to 11, where foreign key support was added to partitioned
tables by commit 3de241dba86f.  (A related change is commit f56f8f8da6af
in pg12 which added support for FKs *referencing* partitioned tables;
this is what forces us to use an ad-hoc recursion mechanism for this.)

Diagnosed by Tom Lane from bug report from Ron L Johnson.  As of this
writing, no reviews were offered.

Discussion: https://postgr.es/m/75fe0761-a291-86a9-c8d8-4906da077469@gmail.com
Discussion: https://postgr.es/m/3144850.1607369633@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6f70d7ca1d1937a9f7b79eff6fb18ed1bb2a4c47

Modified Files
--------------
src/backend/commands/tablecmds.c          | 196 ++++++++++++++++++++++++------
src/test/regress/expected/foreign_key.out |  78 ++++++++++++
src/test/regress/sql/foreign_key.sql      |  75 ++++++++++++
3 files changed, 311 insertions(+), 38 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Have ALTER CONSTRAINT recurse on partitioned tables
@ 2021-05-05 16:23  Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 0 replies; 4+ messages in thread

From: Alvaro Herrera @ 2021-05-05 16:23 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Have ALTER CONSTRAINT recurse on partitioned tables

When ALTER TABLE .. ALTER CONSTRAINT changes deferrability properties
changed in a partitioned table, we failed to propagate those changes
correctly to partitions and to triggers.  Repair by adding a recursion
mechanism to affect all derived constraints and all derived triggers.
(In particular, recurse to partitions even if their respective parents
are already in the desired state: it is possible for the partitions to
have been altered individually.)  Because foreign keys involve tables in
two sides, we cannot use the standard ALTER TABLE recursion mechanism,
so we invent our own by following pg_constraint.conparentid down.

When ALTER TABLE .. ALTER CONSTRAINT is invoked on the derived
pg_constraint object that's automaticaly created in a partition as a
result of a constraint added to its parent, raise an error instead of
pretending to work and then failing to modify all the affected triggers.
Before this commit such a command would be allowed but failed to affect
all triggers, so it would silently misbehave.  (Restoring dumps of
existing databases is not affected, because pg_dump does not produce
anything for such a derived constraint anyway.)

Add some tests for the case.

Backpatch to 11, where foreign key support was added to partitioned
tables by commit 3de241dba86f.  (A related change is commit f56f8f8da6af
in pg12 which added support for FKs *referencing* partitioned tables;
this is what forces us to use an ad-hoc recursion mechanism for this.)

Diagnosed by Tom Lane from bug report from Ron L Johnson.  As of this
writing, no reviews were offered.

Discussion: https://postgr.es/m/75fe0761-a291-86a9-c8d8-4906da077469@gmail.com
Discussion: https://postgr.es/m/3144850.1607369633@sss.pgh.pa.us

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/a25b98d2cf38e0f07898d08fb151b1915e2f4709

Modified Files
--------------
src/backend/commands/tablecmds.c          | 188 ++++++++++++++++++++++++------
src/test/regress/expected/foreign_key.out |  45 ++++++-
src/test/regress/sql/foreign_key.sql      |  43 ++++++-
3 files changed, 240 insertions(+), 36 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Have ALTER CONSTRAINT recurse on partitioned tables
@ 2021-05-05 16:23  Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 0 replies; 4+ messages in thread

From: Alvaro Herrera @ 2021-05-05 16:23 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Have ALTER CONSTRAINT recurse on partitioned tables

When ALTER TABLE .. ALTER CONSTRAINT changes deferrability properties
changed in a partitioned table, we failed to propagate those changes
correctly to partitions and to triggers.  Repair by adding a recursion
mechanism to affect all derived constraints and all derived triggers.
(In particular, recurse to partitions even if their respective parents
are already in the desired state: it is possible for the partitions to
have been altered individually.)  Because foreign keys involve tables in
two sides, we cannot use the standard ALTER TABLE recursion mechanism,
so we invent our own by following pg_constraint.conparentid down.

When ALTER TABLE .. ALTER CONSTRAINT is invoked on the derived
pg_constraint object that's automaticaly created in a partition as a
result of a constraint added to its parent, raise an error instead of
pretending to work and then failing to modify all the affected triggers.
Before this commit such a command would be allowed but failed to affect
all triggers, so it would silently misbehave.  (Restoring dumps of
existing databases is not affected, because pg_dump does not produce
anything for such a derived constraint anyway.)

Add some tests for the case.

Backpatch to 11, where foreign key support was added to partitioned
tables by commit 3de241dba86f.  (A related change is commit f56f8f8da6af
in pg12 which added support for FKs *referencing* partitioned tables;
this is what forces us to use an ad-hoc recursion mechanism for this.)

Diagnosed by Tom Lane from bug report from Ron L Johnson.  As of this
writing, no reviews were offered.

Discussion: https://postgr.es/m/75fe0761-a291-86a9-c8d8-4906da077469@gmail.com
Discussion: https://postgr.es/m/3144850.1607369633@sss.pgh.pa.us

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/abce26c9eb95698c5bd07ae21ce4df5d45e3c02b

Modified Files
--------------
src/backend/commands/tablecmds.c          | 196 ++++++++++++++++++++++++------
src/test/regress/expected/foreign_key.out |  78 ++++++++++++
src/test/regress/sql/foreign_key.sql      |  75 ++++++++++++
3 files changed, 311 insertions(+), 38 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2021-05-05 16:23 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-05-05 16:23 pgsql: Have ALTER CONSTRAINT recurse on partitioned tables Alvaro Herrera <alvherre@alvh.no-ip.org>
2021-05-05 16:23 pgsql: Have ALTER CONSTRAINT recurse on partitioned tables Alvaro Herrera <alvherre@alvh.no-ip.org>
2021-05-05 16:23 pgsql: Have ALTER CONSTRAINT recurse on partitioned tables Alvaro Herrera <alvherre@alvh.no-ip.org>
2021-05-05 16:23 pgsql: Have ALTER CONSTRAINT recurse on partitioned tables Alvaro Herrera <alvherre@alvh.no-ip.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox