pgsql: Fix TRUNCATE .. CASCADE on partitions

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix TRUNCATE .. CASCADE on partitions
Date: 2020-02-07 20:22:14
Message-ID: E1j0A8k-0005G8-NK@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix TRUNCATE .. CASCADE on partitions

When running TRUNCATE CASCADE on a child of a partitioned table
referenced by another partitioned table, the truncate was not applied to
partitions of the referencing table; this could leave rows violating the
constraint in the referencing partitioned table. Repair by walking the
pg_constraint chain all the way up to the topmost referencing table.

Note: any partitioned tables containing FKs that reference other
partitioned tables should be checked for possible violating rows, if
TRUNCATE has occurred in partitions of the referenced table.

Reported-by: Christophe Courtois
Author: Jehan-Guillaume de Rorthais
Discussion: https://postgr.es/m/20200204183906.115f693e@firost

Branch
------
REL_12_STABLE

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

Modified Files
--------------
doc/src/sgml/ref/truncate.sgml | 3 ++
src/backend/catalog/heap.c | 84 +++++++++++++++++++++++++++++++++-
src/test/regress/expected/truncate.out | 50 ++++++++++++++++++++
src/test/regress/sql/truncate.sql | 38 +++++++++++++++
4 files changed, 173 insertions(+), 2 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Stephen Frost 2020-02-07 21:13:39 Re: pg_basebackup and snapshots
Previous Message Andres Freund 2020-02-07 20:21:56 Re: pg_basebackup and snapshots