BUG #3965: UNIQUE constraint fails on long column values

From: "Juho Saarikko" <juhos(at)mbnet(dot)fi>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #3965: UNIQUE constraint fails on long column values
Date: 2008-02-18 11:30:23
Message-ID: 200802181130.m1IBUNdu060026@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-docs


The following bug has been logged online:

Bug reference: 3965
Logged by: Juho Saarikko
Email address: juhos(at)mbnet(dot)fi
PostgreSQL version: 8.3RC2
Operating system: Linux
Description: UNIQUE constraint fails on long column values
Details:

It is impossible to add an UNIQUE constraint which includes columns with
long values. The reason seems to be that UNIQUE is implemented using b-tree
index, which cannot handle values longer than 8191 bytes.

While I didn't test, I'd imagine that this would also mean that any attempt
to insert such values to an already unique column would fail.

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.

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.

Exact error message:
******************
kuvat=# alter table pictures ADD constraint pic_unique unique (safe);
NOTICE: 00000: ALTER TABLE / ADD UNIQUE will create implicit index
"pic_unique" for table "pictures"
LOCATION: DefineIndex, indexcmds.c:434
ERROR: 54000: index row requires 47148 bytes, maximum size is 8191
LOCATION: index_form_tuple, indextuple.c:170

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alexandra Nitzschke 2008-02-18 15:04:20 Bug (#3484) - Missing pg_clog/0AE6
Previous Message Tom Lane 2008-02-17 23:21:14 Re: [PATCH] Don't bail with legitimate -N/-B options

Browse pgsql-docs by date

  From Date Subject
Next Message Gregory Stark 2008-02-18 15:29:44 Re: BUG #3965: UNIQUE constraint fails on long column values
Previous Message Bruce Momjian 2008-02-13 22:44:57 Migration section added