Attempt to fix inheritance limitations: unique and foreign key constraints

Started by Raphael Medaerover 8 years ago3 messageshackers
Jump to latest
#1Raphael Medaer
rme@escaux.com

Hi pg-hackers,

I'm trying to fix some of limitations in table inheritance. My first use
case concerns "referencing" foreign keys in parent table.

The attached patch propagates foreign keys to inherited tables. I'm
automatically cloning foreign keys from parent table into children (with
right dependencies). It's the native implementation of work-around
described in documentation section 5.9.1. (Caveats).

To be honest it's my first pg hack. Thus it might contain (serious)
issues (please be lenient with it).
Furthermore it's not yet documented (TODO !!)

As far as I tested it works pretty well; the internal triggers are
installed on CREATE TABLE .. INHERIT and even after ALTER TABLE .. INHERIT.

If you have few minutes to challenge this hack and give your advices, be
my guest !

Kind regards,

--
Raphael Medaer
Product Development Engineer
Escaux

Escaux, Communication as easy as the web
Chaussée de Bruxelles 408, 1300 Wavre, Belgium
Direct: +3227887564
Main: +3226860900
www.escaux.com <http://www.escaux.com>
------------------------------------------------------------------------
/Dit bericht is onderworpen aan de voorwaarden beschikbaar op onze
website <https://www.escaux.com/docs/ContractInfo.html>.
Ce message est soumis aux conditions disponibles sur notre site web
<https://www.escaux.com/docs/ContractInfo.html>.
This message is subject to the terms and conditions available on our
website <https://www.escaux.com/docs/ContractInfo.html>. /

Attachments:

t38854_1
patch-inheritance-referencing-fk_001.patchtext/x-diff; name=patch-inheritance-referencing-fk_001.patchDownload+232-4
#2Robert Haas
robertmhaas@gmail.com
In reply to: Raphael Medaer (#1)
Re: Attempt to fix inheritance limitations: unique and foreign key constraints

On Tue, Jun 12, 2018 at 11:28 AM, Raphael Medaer <rme@escaux.com> wrote:

Hi pg-hackers,

I'm trying to fix some of limitations in table inheritance. My first use
case concerns "referencing" foreign keys in parent table.

The attached patch propagates foreign keys to inherited tables. I'm
automatically cloning foreign keys from parent table into children (with
right dependencies). It's the native implementation of work-around described
in documentation section 5.9.1. (Caveats).

To be honest it's my first pg hack. Thus it might contain (serious) issues
(please be lenient with it).
Furthermore it's not yet documented (TODO !!)

As far as I tested it works pretty well; the internal triggers are installed
on CREATE TABLE .. INHERIT and even after ALTER TABLE .. INHERIT.

If you have few minutes to challenge this hack and give your advices, be my
guest !

Sounds very similar to commit 3de241dba86f3dd000434f70aebba725fb928032.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#3Raphael Medaer
rme@escaux.com
In reply to: Robert Haas (#2)
Re: Attempt to fix inheritance limitations: unique and foreign key constraints

Hi Robert,

Sounds very similar to commit 3de241dba86f3dd000434f70aebba725fb928032.

I'm reusing part of the code from this commit (mainly
"CloneForeignKeyConstraints")..
But this commit concerns only partitioned tables.. not inherited tables.

Kind regards,

--
Raphael Medaer
Product Development Engineer
Escaux

Escaux, Communication as easy as the web
Chaussée de Bruxelles 408, 1300 Wavre, Belgium
Direct: +3227887564
Main: +3226860900
www.escaux.com <http://www.escaux.com>
------------------------------------------------------------------------
/Dit bericht is onderworpen aan de voorwaarden beschikbaar op onze
website <https://www.escaux.com/docs/ContractInfo.html>.
Ce message est soumis aux conditions disponibles sur notre site web
<https://www.escaux.com/docs/ContractInfo.html>.
This message is subject to the terms and conditions available on our
website <https://www.escaux.com/docs/ContractInfo.html>. /