Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id A6F9CB5DBE0 for ; Wed, 25 May 2011 15:00:11 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 03928-03 for ; Wed, 25 May 2011 18:00:00 +0000 (UTC) X-Greylist: delayed 00:53:19.266821 by SQLgrey-1.7.6 Received: from 27.mail-out.ovh.net (3.27.mail-out.ovh.net [46.105.56.209]) by mail.postgresql.org (Postfix) with SMTP id C31B4B5DBDA for ; Wed, 25 May 2011 14:59:59 -0300 (ADT) Received: (qmail 24905 invoked by uid 503); 25 May 2011 17:56:11 -0000 Received: from b9.ovh.net (HELO mail193.ha.ovh.net) (213.186.33.59) by 27.mail-out.ovh.net with SMTP; 25 May 2011 17:56:06 -0000 Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 25 May 2011 18:59:53 +0200 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO apollo13) (lists%peufeu.com@88.161.102.87) by ns0.ovh.net with SMTP; 25 May 2011 18:59:52 +0200 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Stefan Keller" Cc: mmoncure@gmail.com, pgsql-performance@postgresql.org, "Robert Haas" Subject: Re: FW: KVP table vs. hstore - hstore performance (Was: Postgres NoSQL emulation) References: <4DD06EF3.7030003@postnewspapers.com.au> <99EECF01B5C87A498318776AB7E4A78D3640F59E26@sid00102.hsr.ch> Date: Wed, 25 May 2011 18:59:51 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pierre C" Message-ID: In-Reply-To: User-Agent: Opera Mail/11.10 (Linux) X-Ovh-Tracer-Id: 3857333081053267536 X-Ovh-Remote: 88.161.102.87 (par69-8-88-161-102-87.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|U 0.5/N X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201105/340 X-Sequence-Number: 43849 > You wrote >> Try to create a btree index on "(bench_hstore->bench_id) WHERE >> (bench_hstore->bench_id) IS NOT NULL". > > What do you mean exactly? > => CREATE INDEX myhstore_kps_gin_idx ON myhstore USING gin(kvps) WHERE > ??? IS NOT NULL; > > My table's def is: >> CREATE TABLE myhstore ( id bigint PRIMARY KEY, kvps hstore NOT NULL ); > So I'm doing something like: > CREATE INDEX myhstore_kps_gin_idx ON myhstore USING gin(kvps); Hello ; I meant a plain old btree index like this : CREATE INDEX foo ON myhstore((kvps->'yourkeyname')) WHERE (kvps->'yourkeyname') IS NOT NULL; The idea is that : - The reason to use hstore is to have an arbitrary number of keys and use the keys you want, not have a fixed set of columns like in a table - Therefore, no hstore key is present in all rows (if it was, you'd make it a table column, and maybe index it) - You'll probably only want to index some of the keys/values (avoiding to index values that contain serialized data or other stuff that never appears in a WHERE clause) So, for each key that corresponds to a searchable attribute, I'd use a conditional index on that key, which only indexes the relevant rows. For keys that never appear in a WHERE, no index is needed. gist is good if you want the intersecton of a hstore with another one (for instance), btree is good if you want simple search or range search.