Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id AC2EDB5DC01 for ; Mon, 19 Sep 2011 12:29:08 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 57618-06 for ; Mon, 19 Sep 2011 15:29:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail-bw0-f46.google.com (mail-bw0-f46.google.com [209.85.214.46]) by mail.postgresql.org (Postfix) with ESMTP id 028AAB5DBD1 for ; Mon, 19 Sep 2011 12:29:01 -0300 (ADT) Received: by bkbzt4 with SMTP id zt4so5390899bkb.19 for ; Mon, 19 Sep 2011 08:29:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=hbOnLjOgnRwGTZhEpS6eFPafCgdz/bSwdAybD1j1Juc=; b=QUpwVg4XEVT98mi+o9iUKgLPJudgMnkaoM/xliZ0K9vV1h542vWx4F0J8YHVfZ9nYg YQsrrsTh4Ahby7DND3v7pAuCav1a5L62SnnBOdUHWvgeZeREgA6DdrwXCzuE82N6BHKZ YH/ErW+mXe2+hSdDz3F89M6PmG/SlPBlkmjaQ= Received: by 10.204.154.150 with SMTP id o22mr1695779bkw.363.1316446140755; Mon, 19 Sep 2011 08:29:00 -0700 (PDT) Received: from [10.64.1.26] ([94.45.140.16]) by mx.google.com with ESMTPS id af16sm14489835bkc.10.2011.09.19.08.28.58 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 19 Sep 2011 08:28:59 -0700 (PDT) Message-ID: <4E775FB9.6050704@gmail.com> Date: Mon, 19 Sep 2011 18:28:57 +0300 From: Vitalii Tymchyshyn User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Lightning/1.0b2 Thunderbird/3.1.11 MIME-Version: 1.0 To: Robert Klemme CC: Merlin Moncure , Stefan Keller , Jeff Janes , Peter Geoghegan , pgsql-performance@postgresql.org Subject: Re: Hash index use presently(?) discouraged since 2005: revive or bury it? References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.799 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_ENVFROM_END_DIGIT=0.1, FREEMAIL_FROM=0.001 X-Spam-Level: X-Archive-Number: 201109/270 X-Sequence-Number: 45046 19.09.11 18:19, Robert Klemme написав(ла): > On Mon, Sep 19, 2011 at 4:04 PM, Merlin Moncure wrote: >> >> Postgres's hash index implementation used to be pretty horrible -- it >> stored the pre-hashed datum in the index which, while making it easier >> to do certain things, made it horribly slow, and, for all intents and >> purposes, useless. Somewhat recently,a lot of work was put in to fix >> that -- the index now packs the hash code only which made it >> competitive with btree and superior for larger keys. However, certain >> technical limitations like lack of WAL logging and uniqueness hold >> hash indexing back from being used like it really should be. In cases >> where I really *do* need hash indexing, I do it in userland. >> >> create table foo >> ( >> a_long_field text; >> ); >> create index on foo(hash(a_long_field)); >> >> select * from foo where hash(a_long_field) = hash(some_value) and >> a_long_field = some_value; >> >> This technique works fine -- the main disadvantage is that enforcing >> uniqueness is a PITA but since the standard index doesn't support it >> either it's no great loss. I also have the option of getting >> 'uniqueness' and being able to skip the equality operation if I >> sacrifice some performance and choose a strong digest. Until the hash >> index issues are worked out, I submit that this remains the go-to >> method to do this. > Is this approach (storing the hash code in a btree) really faster than > a regular btree index on "a_long_field"? And if so, for which kind of > data and load? Actually sometimes the field in [potentially] so long, you can't use regular b-tree because it won't fit in the page. Say, it is "text" type. If you will create regular index, you will actually limit column value size to few KB. I am using md5(text) indexes in this case coupled with rather ugly queries (see above). Native support would be nice. Best regards, Vitalii Tymchyshyn.