X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id EAFDC329E50 for ; Mon, 20 Sep 2004 22:02:29 +0100 (BST) 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 12392-10 for ; Mon, 20 Sep 2004 21:02:21 +0000 (GMT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id DF1AD329C63 for ; Mon, 20 Sep 2004 22:02:22 +0100 (BST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 7A1A134FE1; Mon, 20 Sep 2004 14:02:22 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 783CF34F55; Mon, 20 Sep 2004 14:02:22 -0700 (PDT) Date: Mon, 20 Sep 2004 14:02:22 -0700 (PDT) From: Stephan Szabo To: Jaime Casanova Cc: pgsql-admin@postgresql.org Subject: Re: unique constraints on foreign keys In-Reply-To: <20040920204151.87057.qmail@web50008.mail.yahoo.com> Message-ID: <20040920135913.H79243@megazone.bigpanda.com> References: <20040920204151.87057.qmail@web50008.mail.yahoo.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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: 200409/177 X-Sequence-Number: 14880 On Mon, 20 Sep 2004, Jaime Casanova wrote: > I have a reference table that holds all the status > used in a system (it's a very little table just 10 or > 15 rows). > > create table status ( > cod_status char(2) not null primary key, > nam_status text not null > ); > > create table some_other_table ( > ... definition of the table ... > status char(2) not null references status > ); > > ok. This is the idea if a want to do a reference to > the status table i need to create a primary key or a > unique index on the status table. > > Obviously the planner will choose always a seq scan in > such a table (it's obvious to you, it's obvious to me, > but not to the planner), but the planner will > calculate the cost of use the index and will choose > the seq. > So, there is a way to teach the planner always do a > seq on that table and do not ask for use the index? > There is a way to not enforce the creation of a > primary or unique index on a referenced table? Not really. It's not the index that's important per-se, it's the uniqueness that is implied. The SQL spec requires the set of referenced columns to be the set of columns of a unique or primary key on the referenced table and we enforce that. Without that the behavior of all the foreign key types becomes as complicated as the match partial behavior because you have to be able to deal with multiple matching referenced rows.