Re: Multicolumn foreign keys need useless unique indices?

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: Multicolumn foreign keys need useless unique indices?
Дата
Msg-id 20020913080255.D57976-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на Re: Multicolumn foreign keys need useless unique indices?  (Antti Haapala <antti.haapala@iki.fi>)
Список 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.




В списке pgsql-hackers по дате отправления:

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: Multicolumn foreign keys need useless unique indices?
Следующее
От: Hannu Krosing
Дата:
Сообщение: Re: Multicolumn foreign keys need useless unique indices?