Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XVRAN-0003Uu-2B for pgsql-bugs@arkaria.postgresql.org; Sat, 20 Sep 2014 20:21:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XVRAM-0000pE-IC for pgsql-bugs@arkaria.postgresql.org; Sat, 20 Sep 2014 20:21:58 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XVRAL-0000p8-Qm for pgsql-bugs@postgresql.org; Sat, 20 Sep 2014 20:21:57 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XVRAI-0006Z5-Fe for pgsql-bugs@postgresql.org; Sat, 20 Sep 2014 20:21:56 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s8KKLpUv017644; Sat, 20 Sep 2014 16:21:51 -0400 From: Tom Lane 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 In-reply-to: <20140917055723.2495.99190@wrigleys.postgresql.org> References: <20140917055723.2495.99190@wrigleys.postgresql.org> Comments: In-reply-to maxim.boguk@postgresql-consulting.com message dated "Wed, 17 Sep 2014 05:57:23 -0000" Date: Sat, 20 Sep 2014 16:21:51 -0400 Message-ID: <17643.1411244511@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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