Re: BUG #3965: UNIQUE constraint fails on long column values

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Juho Saarikko" <juhos(at)mbnet(dot)fi>
Cc: <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #3965: UNIQUE constraint fails on long column values
Date: 2008-02-18 15:29:44
Message-ID: 87r6famgev.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-docs

"Juho Saarikko" <juhos(at)mbnet(dot)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!

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2008-02-18 19:09:13 Re: BUG #3966: problem with implicit cast array parameter
Previous Message Zdenek Kotala 2008-02-18 15:19:37 Re: Bug (#3484) - Missing pg_clog/0AE6

Browse pgsql-docs by date

  From Date Subject
Next Message Bruce Momjian 2008-02-18 22:12:28 Re: BUG #3965: UNIQUE constraint fails on long column values
Previous Message Juho Saarikko 2008-02-18 11:30:23 BUG #3965: UNIQUE constraint fails on long column values