Skip site navigation (1) Skip section navigation (2)

Indexes and sequences

From: Jeff Willden <jeff(at)pavanell(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Indexes and sequences
Date: 2008-01-19 22:04:34
Message-ID: 51ED13DB-7619-4117-BB85-EE61AFCCAA2F@pavanell.com (view raw or flat)
Thread:
Lists: pgsql-novice
I'm cleaning up a database that someone else made and have a couple  
questions. When I look at a table in pgAdmin it shows the DDL below.  
Do I need an index on the groupid_seq sequence? Doesn't the sequence  
already include one? Also, even if I need it, it doesn't need to be a  
unique index because the sequence already ensures uniqueness, right?  
On top of that there's a primary key constraint that also ensures  
uniqueness. Isn't there a bunch of redundant stuff here?

CREATE TABLE buddygroup
(
   groupid integer NOT NULL DEFAULT nextval('groupid_seq'::text),
   userid integer NOT NULL,
   title character varying(255) NOT NULL,
   CONSTRAINT buddygroup_pkey PRIMARY KEY (groupid)
)
WITH OIDS;
ALTER TABLE buddygroup OWNER TO postgres;

-- Index: bg_groupid_idx

-- DROP INDEX bg_groupid_idx;

CREATE UNIQUE INDEX bg_groupid_idx
   ON buddygroup
   USING btree
   (groupid);

-- Index: bg_userid_idx

-- DROP INDEX bg_userid_idx;

CREATE INDEX bg_userid_idx
   ON buddygroup
   USING btree
   (userid);

Responses

pgsql-novice by date

Next:From: Sean DavisDate: 2008-01-19 22:26:11
Subject: Re: Indexes and sequences
Previous:From: Andrew WinklerDate: 2008-01-19 02:45:01
Subject: Re: domains, types, constraints

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group