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 EA5AE3A482C for ; Tue, 2 Nov 2004 04:23:10 +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 85684-02 for ; Tue, 2 Nov 2004 04:23:07 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 0E9583A482E for ; Tue, 2 Nov 2004 04:23:06 +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 iA24MsUj010362 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 1 Nov 2004 21:22:56 -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 iA24MsDe056727; Mon, 1 Nov 2004 21:22:54 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id iA24MrKh056726; Mon, 1 Nov 2004 21:22:53 -0700 (MST) (envelope-from mfuhr) Date: Mon, 1 Nov 2004 21:22:52 -0700 From: Michael Fuhr To: T E Schmitz Cc: pgsql-sql@postgresql.org, tgl@sss.pgh.pa.us, dev@archonet.com Subject: Re: Join Table Message-ID: <20041102042252.GA56614@winnie.fuhr.org> References: <41866598.5040909@numerixtechnology.de> <20041101170324.GA18943@winnie.fuhr.org> <41867C72.4060001@numerixtechnology.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41867C72.4060001@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/13 X-Sequence-Number: 19332 On Mon, Nov 01, 2004 at 06:12:02PM +0000, T E Schmitz wrote: > I see. If using a multi-column PK, the order matters. > So, if I want to access the table both via the 1st and 2nd PK column, I > would have to define an index for the 2nd column to avoid a full table scan. If you want to use an index scan when querying by the 2nd column alone then you'd need to create an index on it. Queries using the 1st column alone or the 1st column with the 2nd column will use the primary key index. You can use EXPLAIN ANALYZE to see which index, if any, the planner uses. > Let's ask the question the other way round: I remember seeing a > discussion (re Oracle) whether to use a multi-column PK or a unique > constraint in such a situation - I got the impression it is one of these > "religious" discussions ;-). > What are the pros and cons? Here's an excerpt from PostgreSQL's CREATE TABLE documentation: Technically, PRIMARY KEY is merely a combination of UNIQUE and NOT NULL, but identifying a set of columns as primary key also provides metadata about the design of the schema, as a primary key implies that other tables may rely on this set of columns as a unique identifier for rows. -- Michael Fuhr http://www.fuhr.org/~mfuhr/