Re: Deleting vs foreign keys

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: Deleting vs foreign keys
Дата
Msg-id 20051025092537.GF22318@svana.org
обсуждение исходный текст
Ответ на Re: Deleting vs foreign keys  (WireSpot <wirespot@gmail.com>)
Ответы Re: Deleting vs foreign keys  (WireSpot <wirespot@gmail.com>)
Список pgsql-general
On Tue, Oct 25, 2005 at 12:18:34PM +0300, WireSpot wrote:
> On 10/25/05, Michael Fuhr <mike@fuhr.org> wrote:
> > Are there indexes on the foreign key columns?  That is, given
> > the following example,
> >
> > CREATE TABLE foo (id integer PRIMARY KEY);
> > CREATE TABLE bar (fooid integer NOT NULL REFERENCES foo ON DELETE CASCADE);
> >
> > do you have an index on bar.fooid?
>
> There are no indexes on the referring fields in any tables. Would this
> make a huge difference?

If bar is at all large, yes. Consider if you delete something from foo.
The system has to then scan bar to find all matching fooids. If there
is no index on that column it will do a seq scan. If you delete
everything from foo, it will (sequentially) scan bar once for every row
in foo...

BTW, have you considered TRUNCATE? (although it may not work with
foreign keys).

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Вложения

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

Предыдущее
От: Oliver Elphick
Дата:
Сообщение: Re: newbie question: reading sql commands from script
Следующее
От: Csaba Nagy
Дата:
Сообщение: Re: Deleting vs foreign keys