Re: Multicolumn foreign keys need useless unique indices?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Antti Haapala <antti(dot)haapala(at)iki(dot)fi>
Cc: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Multicolumn foreign keys need useless unique indices?
Date: 2002-09-13 15:06:17
Message-ID: 20020913080255.D57976-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 13 Sep 2002, Antti Haapala wrote:

> > > AFAIK, the extra index only slows down my inserts - it basically contains
> > > no usable information...
> >
> > Not 100% true. It will speed up cascade delete and update...
>
> To clarify things:
>
> CREATE TABLE original (
> a int PRIMARY KEY,
> b int
> );
> NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
> 'original_pkey' for table 'original'
> CREATE
>
> CREATE TABLE referencer (
> aref int,
> bref int,
> FOREIGN KEY (aref, bref) REFERENCES original(a, b)
> MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
> );
> NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN
> KEY check(s)
> ERROR: UNIQUE constraint matching given keys for referenced table
> "original" not found

SQL 92 would want you to normalize and remove bref from referencer
since it's redundant. You're storing a reference to a table and
some of the dependent values to that reference in another table.
That's probably the best workaround, although I assume your real
case is more complicated.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jan Wieck 2002-09-13 15:26:40 Re: TOAST docs
Previous Message Alvaro Herrera 2002-09-13 14:57:39 Re: Query having issues...