Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id EC75A476BF8 for ; Mon, 27 Jan 2003 16:15:35 -0500 (EST) Received: from lakemtao03.cox.net (lakemtao03.cox.net [68.1.17.242]) by postgresql.org (Postfix) with ESMTP id 4129A476CED for ; Mon, 27 Jan 2003 16:13:33 -0500 (EST) Received: from [192.168.1.1] ([68.11.66.83]) by lakemtao03.cox.net (InterMail vM.5.01.04.05 201-253-122-122-105-20011231) with ESMTP id <20030127211335.PTRE8666.lakemtao03.cox.net@[192.168.1.1]> for ; Mon, 27 Jan 2003 16:13:35 -0500 Subject: Re: Indexing foreign keys From: Ron Johnson To: PgSQL Performance ML In-Reply-To: <3E35991D.5050704@spaceship.com> References: <3E35991D.5050704@spaceship.com> Content-Type: text/plain Organization: Message-Id: <1043702012.9896.72.camel@haggis> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.1 Date: 27 Jan 2003 15:13:32 -0600 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/361 X-Sequence-Number: 1008 On Mon, 2003-01-27 at 14:39, 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.) When you say "I created an index on those 2 fields", so you mean on the fields in the 400K row table, or on the keys in the "fact tables" that the 400K row table? Also, in IFX, could the creation of the foreign indexes have implicitly created indexes? The reason I ask is that this is what happens in Pg when you create a PK. -- +---------------------------------------------------------------+ | Ron Johnson, Jr. mailto:ron.l.johnson@cox.net | | Jefferson, LA USA http://members.cox.net/ron.l.johnson | | | | "Fear the Penguin!!" | +---------------------------------------------------------------+