Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 7D6A5B5DBBF for ; Wed, 25 May 2011 20:03:59 -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 77378-07 for ; Wed, 25 May 2011 23:03:51 +0000 (UTC) X-Greylist: delayed 00:05:12.120288 by SQLgrey-1.7.6 Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com [209.85.216.181]) by mail.postgresql.org (Postfix) with ESMTP id A1180B5DBDA for ; Wed, 25 May 2011 20:03:51 -0300 (ADT) Received: by qyg14 with SMTP id 14so79152qyg.19 for ; Wed, 25 May 2011 16:03:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=BtIS3ZhFrupQo94uVetI4mnMdXnc0Yny7/9V9LKL/8I=; b=U1TF67n1Mjq6fHMj593Jyq1GixKtOUZLP4gIJtWUsmZemcg0XVsESTmXQoCv2ZvLb/ pK2FM2NG5uEsweXgEvThKrvON1cVoVF0o1rRMzq3xacVcrJzJDwU9KFGO9HmJCmdPou4 r/em3KHn07DbKXxIM5Xcr4yDl6XE1jcuYdQQA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=fjjBqjAw0gFzZ/5vkQ7orZtAS5OocXmyLen/6OA3hjgd6Rnv3iASlqc9SlVJtF7b22 2/L7SVDf39tyGPWFT4nwNilXsjtCT4ONJbsAIslqZxSINEuc2KyJk7cbMwYE6MZoqPvS cLOv4988IChWXpnCOdGv1TpE1HiJcQ/Z2cgJo= MIME-Version: 1.0 Received: by 10.229.69.213 with SMTP id a21mr83081qcj.222.1306364319550; Wed, 25 May 2011 15:58:39 -0700 (PDT) Received: by 10.229.13.75 with HTTP; Wed, 25 May 2011 15:58:39 -0700 (PDT) In-Reply-To: References: <4DD06EF3.7030003@postnewspapers.com.au> <99EECF01B5C87A498318776AB7E4A78D3640F59E26@sid00102.hsr.ch> Date: Thu, 26 May 2011 00:58:39 +0200 Message-ID: Subject: Re: FW: KVP table vs. hstore - hstore performance (Was: Postgres NoSQL emulation) From: Stefan Keller To: Pierre C Cc: mmoncure@gmail.com, pgsql-performance@postgresql.org, Robert Haas Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.898 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201105/354 X-Sequence-Number: 43863 Hi all Thank you to all who answered: That worked: CREATE INDEX planet_osm_point_tags_amenity ON planet_osm_point ((tags->'amenity')) WHERE (tags->'amenity') IS NOT NULL; My problem is, that in fact I don't know which tag to index since I'm running a web admin application where users can enter arbitrary queries. Yours, Stefan 2011/5/25 Pierre C : >> You wrote >>> >>> Try to create a btree index on "(bench_hstore->bench_id) WHERE >>> (bench_hstore->bench_id) IS NOT NULL". >> >> What =C2=A0do you mean exactly? >> =3D> 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 (fo= r > instance), btree is good if you want simple search or range search. >