pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexey Bashtanov <bashtanov@imap.cc>
To: pgsql-bugs@postgresql.org
Subject: index scan is performed when index-only scan is possible (partial index)
Date: Mon, 10 Feb 2014 16:33:43 +0400
Message-ID: <52F8C727.3020409@imap.cc> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Hello!

It seems to me there is a situation where index-only scan is possible 
but not performed.

-----
[ACTIONS]
 > create table t as select a, a % 2 b, a % 2 c from generate_series(1, 
1000000) a order by random();
SELECT 1000000
 > create index t_i1 on t (a, c) where b = 1;
CREATE INDEX
 > analyze t;
ANALYZE
 > EXPLAIN select a from t where a < 10000 and b = 1 order by a;
                              QUERY PLAN
---------------------------------------------------------------------
  Index Scan using t_i1 on t  (cost=0.42..14013.07 rows=5094 width=4)
    Index Cond: (a < 10000)
(2 rows)

 > create index t_i2 on t (a, b) where b = 1;
CREATE INDEX
 > EXPLAIN select a from t where a < 10000 and b = 1 order by a;
                                 QUERY PLAN
--------------------------------------------------------------------------
  Index Only Scan using t_i2 on t  (cost=0.42..14009.07 rows=5094 width=4)
    Index Cond: ((a < 10000) AND (b = 1))
(2 rows)

[EXPECTED]
in both cases index-only scan is performed

[RECEIVED]
in the first case index scan is performed, though index-only scan is 
possible, as no conditions rechecking is required
-----

adding (b=1) expression to index as a column does not help

Regards, Alexey


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



view thread (2+ messages)  latest in thread

Message-ID: <52F8C727.3020409@imap.cc>
Permalink:  ../52F8C727.3020409@imap.cc/
Also on:    postgresql.org/message-id/52F8C727.3020409@imap.cc

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: bashtanov@imap.cc
  Subject: Re: index scan is performed when index-only scan is possible (partial index)
  In-Reply-To: <52F8C727.3020409@imap.cc>
  References: <52F8C727.3020409@imap.cc>

* 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