Re: Indexing foreign keys

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: Indexing foreign keys
Дата
Msg-id 20030127131057.F81562-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на Indexing foreign keys  (Matt Mello <alien@spaceship.com>)
Ответы Re: Indexing foreign keys  (Josh Berkus <josh@agliodbs.com>)
Re: Indexing foreign keys  (Matt Mello <alien@spaceship.com>)
Список pgsql-performance
On Mon, 27 Jan 2003, Matt Mello wrote:

> Due to reasons that everyone can probably intuit, we are porting a large
> server application from IBM Informix to PG.  However, things that take
> milliseconds in IFX are taking HOURS (not joking) in PG.  I *think* I
> may have come across some reasons why, but I would like to see if anyone
> else has an opinion.  I could not find anything relevant in docs (but if
> it is there, please point me to it).
>
> Let me give an example of one of the problems...
>
> I have a table that utilizes 2 foreign keys.  It has 400000 records of
> approximately 512 bytes each (mostly text, except for the keys).  When I
> run a specific query on it, it takes 8000ms to complete, and it always
> does a full scan.
>
> I "assumed" that since I did not have to create an index on those
> foreign key fields in IFX, that I did not have to in PG.  However, just
> for kicks, I created an index on those 2 fields, and my query time
> (after the first, longer attempt, which I presume is from loading an
> index) went from 8000ms to 100ms.
>
> So, do we ALWAYS have to create indexes for foreign key fields in PG?
> Do the docs say this?  (I couldn't find the info.)

You don't always need to create them, because there are fk patterns where
an index is counterproductive, but if you're not in one of those cases you
should create them.  I'm not sure the docs actually say anything about
this however.




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

Предыдущее
От: Ron Johnson
Дата:
Сообщение: Re: Indexing foreign keys
Следующее
От: Josh Berkus
Дата:
Сообщение: Re: Indexing foreign keys