From: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | FKs + partial indexes? |
Date: | 2006-11-22 18:33:21 |
Message-ID: | 456497F1.60505@dunslane.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
I was thinking a bit about a problem that was mentioned in the
discussion TomD, Simon Rigga and I had about enums and foreign keys,
namely that often we find dozens of tiny little reference tables
littering the data model, or else we find a table that somehow
consolidates them, plus some sort of homegrown referential integrity
checks. I wondered if we could improve on that situation by using
partial unique indexes on the consolidated table, and providing a
mechanism to specify which index the FK must refer to (or else allow
allow an optional predicate expression which would have to match the
predicate expression of the partial index).
So we would have something like:
create table constants (type text, id int primary key, value text);
create unique index x_const_idx on constants(id) where type = 'x';
create table client (id serial primary key; xid int references
constants(id) using x_const_idx);
Of course, this is a blue sky idea, and I haven't thought out any
details at all, but it struck me that it might be a way to make designs
a bit cleaner.
cheers
andrew
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Dunstan | 2006-11-22 18:37:57 | Re: FKs + partial indexes? |
Previous Message | Markus Schiltknecht | 2006-11-22 18:23:30 | Integrating Replication into Core |