Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e3jcC-0001Zw-MI for pgsql-bugs@arkaria.postgresql.org; Sun, 15 Oct 2017 14:10:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e3jcB-0005dQ-HU for pgsql-bugs@arkaria.postgresql.org; Sun, 15 Oct 2017 14:10:03 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e3jbT-0004NQ-04 for pgsql-bugs@postgresql.org; Sun, 15 Oct 2017 14:09:19 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e3jbL-0008RS-Lx for pgsql-bugs@postgresql.org; Sun, 15 Oct 2017 14:09:17 +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 v9FE9AJ9006165; Sun, 15 Oct 2017 10:09:10 -0400 From: Tom Lane To: andrew@tao11.riddles.org.uk cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14855: index-only scans not used in simple cases In-reply-to: <20171015122053.8204.93460@wrigleys.postgresql.org> References: <20171015122053.8204.93460@wrigleys.postgresql.org> Comments: In-reply-to andrew@tao11.riddles.org.uk message dated "Sun, 15 Oct 2017 12:20:53 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <6163.1508076550.1@sss.pgh.pa.us> Date: Sun, 15 Oct 2017 10:09:10 -0400 Message-ID: <6164.1508076550@sss.pgh.pa.us> 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 andrew@tao11.riddles.org.uk writes: > Given a unique index on (a) and a (slightly higher cost) index on (a,b), the > query > select a,b from sometable where a=123; > will not do an index-only scan unless the allvisfrac is *exactly* 1.0, and > in the more normal case where only almost all of the pages are all-visible, > it will generate the plain index scan on a instead, with the extra heap > fetch. > This is obviously because cost_index is using ceil(pages_fetched * (1.0 - > baserel->allvisfrac)), and since this is a 1-row fetch then pages_fetched is > still 1 after the adjustment for any value of allvisfrac less than exactly > 1.0. One idea is to remove the allvisfrac correction from the pages_fetched calculation altogether, and instead apply it to the I/O cost numbers at the end, ie max_IO_cost *= (1.0 - baserel->allvisfrac); min_IO_cost *= (1.0 - baserel->allvisfrac); just before the partial_path stanza. While that would improve your particular complaint I'm not sure if it's a good idea in general. 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