pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: andrew@tao11.riddles.org.uk
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14855: index-only scans not used in simple cases
Date: Sun, 15 Oct 2017 10:09:10 -0400
Message-ID: <6164.1508076550@sss.pgh.pa.us> (raw)
In-Reply-To: <20171015122053.8204.93460@wrigleys.postgresql.org>
References: <20171015122053.8204.93460@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (2+ messages)

Message-ID: <6164.1508076550@sss.pgh.pa.us>
Permalink:  ../6164.1508076550@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/6164.1508076550@sss.pgh.pa.us

 · 

reply

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, andrew@tao11.riddles.org.uk
  Subject: Re: BUG #14855: index-only scans not used in simple cases
  In-Reply-To: <6164.1508076550@sss.pgh.pa.us>
  References: <20171015122053.8204.93460@wrigleys.postgresql.org> <6164.1508076550@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