Re: Difference between UNIQUE constraint vs index

From: "Jim C(dot) Nasby" <jim(at)nasby(dot)net>
To: John Jawed <johnjawed(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Difference between UNIQUE constraint vs index
Date: 2007-02-28 00:56:20
Message-ID: 20070228005620.GE62448@nasby.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Feb 27, 2007 at 06:43:51PM -0600, John Jawed wrote:
> Is there any difference as far as when the "uniqueness" of values is
> checked in DML between a unique index vs a unique constraint? Or is
> the only difference syntax between unique indices and constraints in
> PostgreSQL?

Syntax only, AFAIK. I prefer using constraints if I actually want to
constrain the data; it makes it clear that it's a restriction.

In some databases if you know that an index just happens to be unique
you might gain some query performance by defining the index as unique,
but I don't think the PostgreSQL planner is that smart. There can also
be some additional overhead involved with a unique index (vs
non-unique), such as when two backends try and add the same key at the
same time (one of them will have to block).
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2007-02-28 00:58:39 Re: Difference between UNIQUE constraint vs index
Previous Message Joseph S 2007-02-28 00:44:45 Re: Slony subscription problem