agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Tom Lane <tgl@sss.pgh.pa.us>
To: adam <adhamm31@hotmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: posgres optimizer not using the index on hstore HELP
Date: Tue, 19 Jul 2016 18:06:50 -0400
Message-ID: <16532.1468966010@sss.pgh.pa.us> (raw)
In-Reply-To: <1468855122279-5912464.post@n5.nabble.com>
References: <1468855122279-5912464.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>
adam <adhamm31@hotmail.com> writes:
> I have a simple query select on the hstore attribute "EMAIL_ADDRESS". but the
> thing is i'm using a parameter in the query to specify which hstore
> attribute I want to access, and when using a parameter the index which I
> created is suppressed; whereas when I hard code the attribute
> "EMAIL_ADDRESS" then the index is used.
WFM:
regression=# create extension hstore;
CREATE EXTENSION
regression=# create table foo(f1 hstore);
CREATE TABLE
regression=# create index on foo ((f1->'bar'));
CREATE INDEX
regression=# explain select * from foo where f1->'bar' = 'baz';
QUERY PLAN
---------------------------------------------------------------------------
Bitmap Heap Scan on foo (cost=4.21..14.37 rows=7 width=32)
Recheck Cond: ((f1 -> 'bar'::text) = 'baz'::text)
-> Bitmap Index Scan on foo_expr_idx (cost=0.00..4.21 rows=7 width=0)
Index Cond: ((f1 -> 'bar'::text) = 'baz'::text)
(4 rows)
regression=# prepare p as select * from foo where f1->$1 = $2;
PREPARE
regression=# explain execute p('bar', 'baz');
QUERY PLAN
---------------------------------------------------------------------------
Bitmap Heap Scan on foo (cost=4.21..14.37 rows=7 width=32)
Recheck Cond: ((f1 -> 'bar'::text) = 'baz'::text)
-> Bitmap Index Scan on foo_expr_idx (cost=0.00..4.21 rows=7 width=0)
Index Cond: ((f1 -> 'bar'::text) = 'baz'::text)
(4 rows)
As a general rule, when you haven't mentioned the PG version you're using
nor provided an *exact* example of what you're doing, it's difficult to
offer useful help.
regards, tom lane
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
view thread (3+ messages)
Message-ID: <16532.1468966010@sss.pgh.pa.us>
Permalink: ../16532.1468966010@sss.pgh.pa.us/
Also on: postgresql.org/message-id/16532.1468966010@sss.pgh.pa.us
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-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, adhamm31@hotmail.com
Subject: Re: posgres optimizer not using the index on hstore HELP
In-Reply-To: <16532.1468966010@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox