From: Tom Lane <tgl@sss.pgh.pa.us>
To: maxim.boguk@postgresql-consulting.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #11441: Weird (and seems wrong) behavior of partial indexes with order by/limit
Date: Sat, 20 Sep 2014 16:21:51 -0400
Message-ID: <17643.1411244511@sss.pgh.pa.us> (raw)
In-Reply-To: <20140917055723.2495.99190@wrigleys.postgresql.org>
References: <20140917055723.2495.99190@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
maxim.boguk@postgresql-consulting.com writes:
> create index qqq_test_2_key on qqq_test(resume_id, is_finished) where
> (is_finished = ANY (ARRAY[0, 5]));
> (postgres@[local]:5432)=# explain analyze select * from qqq_test where
> is_finished = ANY (ARRAY[0, 5]) order by resume_id limit 1;
> [ doesn't use the index ]
The reason why not is that it starts by generating a path that uses the
is_finished = ANY() clause as an indexqual, and decides that such a
path will not produce data that's ordered by resume_id. Which is correct:
it won't, because there will first be a scan to find the is_finished = 0
data and then another scan to find the is_finished = 5 data.
Now in point of fact, we don't need to use that clause as an indexqual
because it's implied by the index predicate. However, indxpath.c has
never tested for such cases and I'm a bit hesitant to add the cycles that
would be required to do so. This sort of case doesn't really seem
compelling enough to justify slowing down planning for *every* query on
tables having partial indexes, which would be the likely outcome. If it
were compelling, we'd have heard about it before ...
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, maxim.boguk@postgresql-consulting.com
Subject: Re: BUG #11441: Weird (and seems wrong) behavior of partial indexes with order by/limit
In-Reply-To: <17643.1411244511@sss.pgh.pa.us>
References: <20140917055723.2495.99190@wrigleys.postgresql.org> <17643.1411244511@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