Re: Query doesn't use index on hstore column

From: "ktm(at)rice(dot)edu" <ktm(at)rice(dot)edu>
To: Michael Barker <mikeb01(at)gmail(dot)com>
Cc: pgsql-performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Query doesn't use index on hstore column
Date: 2014-12-04 21:46:25
Message-ID: 20141204214625.GG20516@aart.rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2014-12-05 01:32:50 Re: Query doesn't use index on hstore column
Previous Message Michael Barker 2014-12-04 20:42:20 Query doesn't use index on hstore column