X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8EABB3A4588 for ; Mon, 1 Nov 2004 17:03:49 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 89388-09 for ; Mon, 1 Nov 2004 17:03:42 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 540883A4570 for ; Mon, 1 Nov 2004 17:03:41 +0000 (GMT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id iA1H3ONZ009861 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 1 Nov 2004 10:03:26 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id iA1H3OPp019010; Mon, 1 Nov 2004 10:03:24 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id iA1H3Orr019009; Mon, 1 Nov 2004 10:03:24 -0700 (MST) (envelope-from mfuhr) Date: Mon, 1 Nov 2004 10:03:24 -0700 From: Michael Fuhr To: T E Schmitz Cc: pgsql-sql Subject: Re: Join Table Message-ID: <20041101170324.GA18943@winnie.fuhr.org> References: <41866598.5040909@numerixtechnology.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41866598.5040909@numerixtechnology.de> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/8 X-Sequence-Number: 19327 On Mon, Nov 01, 2004 at 04:34:32PM +0000, T E Schmitz wrote: > > I have created the following join table: the two FKs are the PK of the > table. Typically, I will need to select rows for a given ITEM_FK. > > Question: is it necessary/advisable to create an index for the ITEM_FK > column? Or is this redundantbecause this column is already one of the PK > columns? Here's an excerpt from the documentation for CREATE TABLE: "PostgreSQL automatically creates an index for each unique constraint and primary key constraint to enforce the uniqueness. Thus, it is not necessary to create an explicit index for primary key columns." However, read the "Multicolumn Indexes" section in the "Indexes" chapter to be sure you understand when the index will be used and when it won't be: http://www.postgresql.org/docs/7.4/static/indexes-multicolumn.html > CREATE TABLE SUPPLY > ( > ITEM_FK integer NOT NULL, > CONTACT_FK integer NOT NULL, > COST numeric (7,2), > PRIMARY KEY (ITEM_FK,CONTACT_FK) > ); If ITEM_FK and CONTACT_FK are foreign keys, then you might want to add foreign key constraints to ensure referential integrity. -- Michael Fuhr http://www.fuhr.org/~mfuhr/