PostgreSQL and inherits

From: Jan Johansson <jan(dot)johansson(dot)mr(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: PostgreSQL and inherits
Date: 2016-05-19 09:53:01
Message-ID: CAGbXvMbMK8PZAQWn1tK3vZnaCMxcSnwyfR4_v8r-rKTXqd9SqA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I want to discuss about inherits in PostgreSQL.
Everything I write here is my own opinion, but I hope for a good dialog.

I think that inherits is a feature to good to be plain legacy, but it is
unfortunately riddled with some inconsistencies. The inheritance keyword
link tables together in a "is-a" chain, from child up to parent. The
children has the same fields as the parent, plus their own (if they
declare).

In one way there is an illusion of object orientation, where the children
share data with the parent (comes from when you select from a parent in the
inheritance and you see the data), but in another way if you use the
condition "only" (in select) or discover that field behavior (primary key,
foreign key, etc) is not inherited, then inheritance is of the behavior of
interface.

It's like the implementation sits on the fence, and does not know if
inherits is object oriented, or if it is interface oriented.

This inconsistency makes the feature not as smooth as it could be.

A suggestion would be to walk down the path for the object oriented
approach, meaning that fields shared with the parent, also share behavior
(primary key, foreign key, etc). This suggestion might break compatibility
with some implementations (using inheritance and where coding has been done
to account for the object-interface-oriented approach).

Another suggestion would be to walk down the path for the interface
oriented approach, meaning that nothing is shared between the child and
parent, except for the field name and types. This may also break
compatibility.

The third suggestion would be to let inheritance be as it is, but to
introduce "extends" keyword to make a more clean object-oriented approach
to the "is-a" chain. Then nothing is broken, but it adds complexity to the
schema.

I'd be happy to know your reflections about the subject.

Kind regards

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2016-05-19 10:29:33 Re: Declarative partitioning
Previous Message Amit Langote 2016-05-19 08:34:53 pg_xlogfile_name_offset() et al and recovery