Re: Questions about indexes?

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ryan Bradetich <rbradetich@uswest.net>
Cc: pgsql-hackers@postgresql.org
Date: 2003-02-17T06:34:50Z
Lists: pgsql-hackers
Ryan Bradetich <rbradetich@uswest.net> writes:
> Although the table schema is immaterial, I will provide it so we have a
> common framework for this discussion:

> 	host_id		integer 	(not null)
> 	timestamp	datetime	(not null)
> 	category	text		(not null)	[<=    5 chars]
> 	anomaly		text		(not null)	[<= 1024 chars]

> This table is used to store archived data, so each row in the table must
> be unique.  Currently I am using a primary key across each column to
> enforce this uniqueness.

It's not real clear to me why you bother enforcing a constraint that the
complete row be unique.  Wouldn't a useful constraint be that the first
three columns be unique?  Even if that's not correct, what's wrong with
tolerating a few duplicates?  You can't tell me it's to save on storage
;-)

> I am not sure why all the data is duplicated in the index ... but i bet
> it has to do with performance since it would save a lookup in the main
> table.

An index that can't prevent looking into the main table wouldn't be
worth anything AFAICS ...

			regards, tom lane