Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id F0CE2476997 for ; Mon, 27 Jan 2003 15:40:22 -0500 (EST) Received: from txsmtp03.texas.rr.com (ms-smtp-03.texas.rr.com [24.93.36.231]) by postgresql.org (Postfix) with ESMTP id B28F6476B7D for ; Mon, 27 Jan 2003 15:39:56 -0500 (EST) Received: from spaceship.com (cs24243214-140.austin.rr.com [24.243.214.140]) by txsmtp03.texas.rr.com (8.12.5/8.12.2) with ESMTP id h0RKZxEL003881 for ; Mon, 27 Jan 2003 15:35:59 -0500 (EST) Message-ID: <3E35991D.5050704@spaceship.com> Date: Mon, 27 Jan 2003 14:39:57 -0600 From: Matt Mello User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Indexing foreign keys Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/357 X-Sequence-Number: 1004 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.) I will create other threads for my other issues. Thanks! -- Matt Mello