From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Jehan-Guillaume de Rorthais <jgdr@dalibo.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: FK violation in partitioned table after truncating a referenced partition
Date: Thu, 6 Feb 2020 18:12:38 -0300
Message-ID: <20200206211238.GA29108@alvherre.pgsql> (raw)
In-Reply-To: <20200204183906.115f693e@firost>
On 2020-Feb-04, Jehan-Guillaume de Rorthais wrote:
> Please, find in attachment a bug fix proposal where a truncate on a
> partition cascade to the referencing table and truncate all its
> partitions if applicable.
>
> The patch make sure heap_truncate_find_FKs find all referencing relations,
> directly **and indirectly** through their parent table.
>
> When considering the various way of fixing this, I thought about calling
> find_all_inheritors on all relations returned by heap_truncate_find_FKs to add
> them to the list or relation to truncate (I have a working patch for this as
> well). However, I felt like heap_truncate_find_FKs was the real suspect here
> and was responsible to find all referencing relations.
Hello, thanks for reporting and patching.
I agree that patching heap_truncate_find_FKs is a reasonable way to fix.
I propose a slightly different formulation: instead of the loop that you
have, we can just use the second loop, and add more parent constraints
to the list if any constraint we scan in turn has a parent constraint.
So we don't repeat the whole thing, but only that second loop.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
[text/x-diff] v2-0001-Fix-TRUNCATE-on-a-partition-to-apply-CASCADE-to-p.patch (0B, ../20200206211238.GA29108@alvherre.pgsql/2-v2-0001-Fix-TRUNCATE-on-a-partition-to-apply-CASCADE-to-p.patch)
download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: alvherre@2ndquadrant.com, jgdr@dalibo.com, pgsql-bugs@lists.postgresql.org
Subject: Re: FK violation in partitioned table after truncating a referenced partition
In-Reply-To: <20200206211238.GA29108@alvherre.pgsql>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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