pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Jaime Casanova <systemguards@yahoo.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: unique constraints on foreign keys
Date: Mon, 20 Sep 2004 14:02:22 -0700 (PDT)
Message-ID: <20040920135913.H79243@megazone.bigpanda.com> (raw)
In-Reply-To: <20040920204151.87057.qmail@web50008.mail.yahoo.com>
References: <20040920204151.87057.qmail@web50008.mail.yahoo.com>


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.





view thread (4+ messages)  latest in thread

Message-ID: <20040920135913.H79243@megazone.bigpanda.com>
Permalink:  ../20040920135913.H79243@megazone.bigpanda.com/
Also on:    postgresql.org/message-id/20040920135913.H79243@megazone.bigpanda.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: sszabo@megazone.bigpanda.com, systemguards@yahoo.com
  Subject: Re: unique constraints on foreign keys
  In-Reply-To: <20040920135913.H79243@megazone.bigpanda.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox