Re: BUG #3965: UNIQUE constraint fails on long column values - Mailing list pgsql-bugs

From Gregory Stark
Subject Re: BUG #3965: UNIQUE constraint fails on long column values
Date
Msg-id 87r6famgev.fsf@oxford.xeocode.com
Whole thread Raw
In response to BUG #3965: UNIQUE constraint fails on long column values  ("Juho Saarikko" <juhos@mbnet.fi>)
List pgsql-bugs
"Juho Saarikko" <juhos@mbnet.fi> writes:

> It is propably impossible to fix this in a simple way, since it is an
> inherent result of the underlying storage specification rather than a mere
> programming error, so the documentation needs to be updated to warn about
> this.

Point taken.


> I suggest implementing unique hash indexes and automatically creating one
> (and turning the b-tree index into a non-unique one) when a large value is
> inserted to fix this. Alternatively, fix b-trees so they can handle large
> values; however, a hash index should be far more efficient for this specific
> case, since the size of a hash is independent of pre-hash data size.

With expression indexes you can do this yourself with something like
 CREATE INDEX pk_hash on tab ((hashtext(safe)))

We can't do this automatically since it wouldn't enforce the UNIQUE
constraint. Conceivably we could actually do something about that but there's
nothing like that now.

We have hash indexes too but in practice a btree over a hash seems to work
just as well or better.

--
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com
  Ask me about EnterpriseDB's PostGIS support!

pgsql-bugs by date:

Previous
From: Zdenek Kotala
Date:
Subject: Re: Bug (#3484) - Missing pg_clog/0AE6
Next
From: Tom Lane
Date:
Subject: Re: BUG #3966: problem with implicit cast array parameter