From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alexey Bashtanov <bashtanov@imap.cc>
Cc: pgsql-bugs@postgresql.org
Subject: Re: index scan is performed when index-only scan is possible (partial index)
Date: Mon, 10 Feb 2014 11:04:36 -0500
Message-ID: <11283.1392048276@sss.pgh.pa.us> (raw)
In-Reply-To: <52F8C727.3020409@imap.cc>
References: <52F8C727.3020409@imap.cc>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Alexey Bashtanov <bashtanov@imap.cc> writes:
>>> 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
>>> EXPLAIN select a from t where a < 10000 and b = 1 order by a;
> [ doesn't do index-only scan ]
Yeah, see the comment in check_index_only():
/*
* Check that all needed attributes of the relation are available from the
* index.
*
* XXX this is overly conservative for partial indexes, since we will
* consider attributes involved in the index predicate as required even
* though the predicate won't need to be checked at runtime. (The same is
* true for attributes used only in index quals, if we are certain that
* the index is not lossy.) However, it would be quite expensive to
* determine that accurately at this point, so for now we take the easy
* way out.
*/
This code knows that b is referenced in the query, which would ordinarily
defeat using an index-only scan with this index. There's no very good way
to tell that the only such reference is in a qual that we will later
decide doesn't need to be checked at runtime.
So, yeah, it'd be nice if that worked ... but don't hold your breath.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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: tgl@sss.pgh.pa.us, bashtanov@imap.cc
Subject: Re: index scan is performed when index-only scan is possible (partial index)
In-Reply-To: <11283.1392048276@sss.pgh.pa.us>
References: <52F8C727.3020409@imap.cc> <11283.1392048276@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 DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox