Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XweEJ-0000Za-UU for pgsql-performance@arkaria.postgresql.org; Thu, 04 Dec 2014 21:46:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XweEJ-0007tP-EB for pgsql-performance@arkaria.postgresql.org; Thu, 04 Dec 2014 21:46:31 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XweEI-0007tI-6h for pgsql-performance@postgresql.org; Thu, 04 Dec 2014 21:46:30 +0000 Received: from proofpoint2.mail.rice.edu ([128.42.201.101] helo=pp2.rice.edu) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XweEE-0003rA-SX for pgsql-performance@postgresql.org; Thu, 04 Dec 2014 21:46:28 +0000 Received: from pps.filterd (pp2.rice.edu [127.0.0.1]) by pp2.rice.edu (8.14.5/8.14.5) with SMTP id sB4Lg8kJ014074; Thu, 4 Dec 2014 15:46:25 -0600 Received: from mh2.mail.rice.edu (mh2.mail.rice.edu [128.42.201.21]) by pp2.rice.edu with ESMTP id 1r2un4880n-1; Thu, 04 Dec 2014 15:46:25 -0600 X-Virus-Scanned: by amavis-2.7.0 at mh2.mail.rice.edu, auth channel X-SMTP-Auth: no X-SMTP-Auth: no Received: from aart.rice.edu (aart.rice.edu [168.7.56.48]) by mh2.mail.rice.edu (Postfix) with ESMTP id 46068500162; Thu, 4 Dec 2014 15:46:25 -0600 (CST) Received: by aart.rice.edu (Postfix, from userid 18612) id 31AFD10072C; Thu, 4 Dec 2014 15:46:25 -0600 (CST) Date: Thu, 4 Dec 2014 15:46:25 -0600 From: "ktm@rice.edu" To: Michael Barker Cc: pgsql-performance Subject: Re: Query doesn't use index on hstore column Message-ID: <20141204214625.GG20516@aart.rice.edu> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-12-10) X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1412040197 X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On Fri, Dec 05, 2014 at 09:42:20AM +1300, Michael Barker wrote: > 1) Created table with hstore column and btree index. > > barkerm=# \d audit > Table "public.audit" > Column | Type | > Modifiers > ---------------+-----------------------------+---------------------------------------------------- > id | integer | not null default > nextval('audit_id_seq'::regclass) > principal_id | integer | > created_at | timestamp without time zone | > root | character varying(255) | > template_code | character(3) | > attributes | hstore | > args | character varying(255)[] | > Indexes: > "audit_pkey" PRIMARY KEY, btree (id) > "audit_attributes_idx" btree (attributes) > > ... > 5) Explain query using the attributes column in the where clause (uses Seq > Scan). > > barkerm=# explain analyse select * from audit where attributes->'accountId' > = '1879355460'; > QUERY PLAN > > ------------------------------------------------------------------------------------------------------------ > Seq Scan on audit (cost=0.00..35409.00 rows=5000 width=133) (actual > time=114.314..218.821 rows=1 loops=1) > Filter: ((attributes -> 'accountId'::text) = '1879355460'::text) > Rows Removed by Filter: 999999 > Planning time: 0.074 ms > Execution time: 218.843 ms > (5 rows) > Hi Michael, I think your index definitions need to be on the particular attribute from attributes and not attributes itself. That works but it does not apply to the query you show above. I think that the binary json type in 9.4 will do what you want. I have not worked with it myself, just looked at the docs. Regards, Ken -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance