pgsql: Fix FK checks of TRUNCATE involving partitioned tables

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix FK checks of TRUNCATE involving partitioned tables
Date: 2018-07-12 16:26:17
Message-ID: E1fdeQ5-0007F1-1r@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix FK checks of TRUNCATE involving partitioned tables

When truncating a table that is referenced by foreign keys in
partitioned tables, the check to ensure the referencing table are also
truncated spuriously failed. This is because it was relying on
relhastriggers as a proxy for the table having FKs, and that's wrong for
partitioned tables. Fix it to consider such tables separately. There
may be a better way ... but this code is pretty inefficient already.

Author: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Reviewed-by: Michael Paquiër <michael(at)paquier(dot)xyz>
Discussion: https://postgr.es/m/20180711000624.zmeizicibxeehhsg@alvherre.pgsql

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/727196ced2423008bb25d7775c4e3b7fca063c8b

Modified Files
--------------
src/backend/catalog/heap.c | 7 +++-
src/backend/commands/tablecmds.c | 2 +-
src/test/regress/expected/truncate.out | 75 ++++++++++++++++++++++++++++++++++
src/test/regress/sql/truncate.sql | 47 +++++++++++++++++++++
4 files changed, 128 insertions(+), 3 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2018-07-12 16:29:22 pgsql: Doc: minor improvement in pl/pgsql FETCH/MOVE documentation.
Previous Message Tom Lane 2018-07-12 15:14:14 pgsql: Doc: update documentation for requirement of ORDER BY in GROUPS