Re: Query doesn't use index on hstore column - Mailing list pgsql-performance

From ktm@rice.edu
Subject Re: Query doesn't use index on hstore column
Date
Msg-id 20141204214625.GG20516@aart.rice.edu
Whole thread Raw
In response to Query doesn't use index on hstore column  (Michael Barker <mikeb01@gmail.com>)
List 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


pgsql-performance by date:

Previous
From: Michael Barker
Date:
Subject: Query doesn't use index on hstore column
Next
From: Tom Lane
Date:
Subject: Re: Query doesn't use index on hstore column