pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: ktm@rice.edu <ktm@rice.edu>
To: Michael Barker <mikeb01@gmail.com>
Cc: pgsql-performance <pgsql-performance@postgresql.org>
Subject: Re: Query doesn't use index on hstore column
Date: Thu, 4 Dec 2014 15:46:25 -0600
Message-ID: <20141204214625.GG20516@aart.rice.edu> (raw)
In-Reply-To: <CALwNKeTZyva2ev5dFDXs4PX01yk27Rk5-UCSYhCWh+jnyDTNNA@mail.gmail.com>
References: <CALwNKeTZyva2ev5dFDXs4PX01yk27Rk5-UCSYhCWh+jnyDTNNA@mail.gmail.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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


-- 
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance



view thread (4+ messages)  latest in thread

Message-ID: <20141204214625.GG20516@aart.rice.edu>
Permalink:  ../20141204214625.GG20516@aart.rice.edu/
Also on:    postgresql.org/message-id/20141204214625.GG20516@aart.rice.edu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: ktm@rice.edu, mikeb01@gmail.com
  Subject: Re: Query doesn't use index on hstore column
  In-Reply-To: <20141204214625.GG20516@aart.rice.edu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox