Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WCtLf-00017e-4K for pgsql-bugs@arkaria.postgresql.org; Mon, 10 Feb 2014 16:04:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WCtLe-0005wo-Je for pgsql-bugs@arkaria.postgresql.org; Mon, 10 Feb 2014 16:04:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WCtLd-0005vm-HI for pgsql-bugs@postgresql.org; Mon, 10 Feb 2014 16:04:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WCtLb-0002R3-16 for pgsql-bugs@postgresql.org; Mon, 10 Feb 2014 16:04:41 +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 s1AG4awB011284; Mon, 10 Feb 2014 11:04:36 -0500 From: Tom Lane To: Alexey Bashtanov cc: pgsql-bugs@postgresql.org 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> Comments: In-reply-to Alexey Bashtanov message dated "Mon, 10 Feb 2014 16:33:43 +0400" Date: Mon, 10 Feb 2014 11:04:36 -0500 Message-ID: <11283.1392048276@sss.pgh.pa.us> X-Pg-Spam-Score: -2.5 (--) 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 Alexey Bashtanov 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