Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 0FD762E0084 for ; Thu, 8 May 2008 17:24:17 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 10239-02-7 for ; Thu, 8 May 2008 17:24:10 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from 30.mail-out.ovh.net (30.mail-out.ovh.net [213.186.62.213]) by developer.postgresql.org (Postfix) with SMTP id 9D5022E0078 for ; Thu, 8 May 2008 17:03:36 -0300 (ADT) Received: (qmail 759 invoked by uid 503); 8 May 2008 19:57:16 -0000 Received: from unknown (HELO mail243.ha.ovh.net) (213.186.33.59) by 30.mail-out.ovh.net with SMTP; 8 May 2008 19:57:16 -0000 Received: from b0.ovh.net (HELO queue-out) (213.186.33.50) by b0.ovh.net with SMTP; 8 May 2008 19:56:53 -0000 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO apollo13.peufeu.com) (88.161.102.87) by ns0.ovh.net with SMTP; 8 May 2008 19:56:52 -0000 Date: Thu, 08 May 2008 22:02:47 +0200 To: "Campbell, Lance" , pgsql-performance@postgresql.org Subject: Re: Creating a foreign key From: PFC Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: User-Agent: Opera Mail/9.24 (Linux) X-Ovh-Tracer-Id: 6558366958937310918 X-Ovh-Remote: 88.161.102.87 (par69-8-88-161-102-87.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|H 0.5/N X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.659 tagged_above=0 required=5 tests=AWL=0.659 X-Spam-Level: X-Archive-Number: 200805/132 X-Sequence-Number: 30100 > When you create a foreign key to a table is there an index that is > created on the foreign key automatically? No, Postgres doesn't do it for you, because if you create (ref_id) references table.id, you will perhaps create an index on (ref_id, date) which would then fill the purpose (and other purposes), or perhaps your table will have 10 rows (but postgres doesnt' know that when you create it) and having an index would be useless, or your table could have many rows but only a few distinct referenced values, in which case again the index would only slow things down. PG does not presume to know better than yourself what you're gonna do with your data ;) UNIQUE and PRIMARY KEY do create UNIQUE INDEXes, of course.