Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id C55372E0039 for ; Mon, 18 Feb 2008 11:29:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 73312-04 for ; Mon, 18 Feb 2008 11:29:48 -0400 (AST) Received: from oxford.xeocode.com (unknown [62.232.55.118]) by postgresql.org (Postfix) with ESMTP id 2CF0F2E003A for ; Mon, 18 Feb 2008 11:29:49 -0400 (AST) Received: from localhost ([127.0.0.1] helo=oxford.xeocode.com) by oxford.xeocode.com with esmtp (Exim 4.69) (envelope-from ) id 1JR7w8-0001mb-5z; Mon, 18 Feb 2008 15:29:44 +0000 To: "Juho Saarikko" Cc: Subject: Re: BUG #3965: UNIQUE constraint fails on long column values In-Reply-To: <200802181130.m1IBUNdu060026@wwwmaster.postgresql.org> (Juho Saarikko's message of "Mon\, 18 Feb 2008 11\:30\:23 GMT") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX.bugs" 2291) References: <200802181130.m1IBUNdu060026@wwwmaster.postgresql.org> From: Gregory Stark Organization: EnterpriseDB Date: Mon, 18 Feb 2008 15:29:44 +0000 Message-ID: <87r6famgev.fsf@oxford.xeocode.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/163 X-Sequence-Number: 19730 "Juho Saarikko" 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!