Inheritance, Primary Keys and Foreign Keys

From: Albert Cervera Areny <albertca(at)hotpop(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Inheritance, Primary Keys and Foreign Keys
Date: 2006-05-08 23:20:21
Message-ID: 200605090120.21802.albertca@hotpop.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,
I'm developing an object persistency framework for which I'd love to have
better support for inheritance in PostgreSQL. I could already map subclasses
with the current inheritance facilities, but the problem is with Primary and
Foreign Keys.

There's a TODO for implementing Indexes that hold information contained in
different tables, but that seems to be difficult because of the need to
create a new index structure. The new structure shouldn't be used by tables
that don't have inherited tables because the new structure would hold a
pointer to the appropiate table per entry and thus redundant in these cases.
Even more, I've seen pointed by Tom Lane in a previous thread, that this
would cause lock problems where a lock in a table is needed, as locking a
table means locking its indexes.

In my particular case (don't know about the SQL standard or other cases),
it'd be enough if when an inherited table is created:
- A primary key in the inherited table is created with the same columns as
the super table.
- A trigger is created in the new table that ensures that this primary key
doesn't exist in the super table.
- A trigger is created in the super table that ensures that this primary key
doesn't exist in it's sub tables.

As I'm not an expert at all, I don't know if these would cause some side
effects or if it's a good enough solution for the general problem. I don't
know how multiple inheritance of tables with primary keys should be held
(maybe all super tables should have the same primary key).

For foreign keys, it seems as if simply selecting FROM a table instead of
the current FROM ONLY would have the expected (by me :) behaviour.

I'm very interested in improving inheritance support in PostgreSQL, and I'm
willing to learn the current design and implementation in order to do it
myself, or help wherever possible. So I'd like to know your ideas or problems
you may find with this solution (if it's a solution at all :)

Thanks in advance!

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeffrey Tenny 2006-05-08 23:35:15 Re: performance question (something to do w/ parameterized
Previous Message Tom Lane 2006-05-08 23:13:52 Re: BTree on-disk page ordering