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@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance