Re: cost_index()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Teodor Sigaev <teodor(at)sigaev(dot)ru>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: cost_index()
Date: 2014-10-27 15:00:44
Message-ID: 20454.1414422044@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Teodor Sigaev <teodor(at)sigaev(dot)ru> writes:
> if (indexonly)
> pages_fetched = ceil(pages_fetched * (1.0 - baserel->allvisfrac));

> As I understand the code, index_pages_fetched() returns summary of page's read
> for index and heap together.

No. Costs for touching the index were computed by the amcostestimate
function; this code is solely about estimating costs for touching the
heap.

> But on next line this recalculates with "all
> visible fraction" of heap. After recent vacuum it could be 1.0 and then
> pages_fetches will be zero. It seems to me obviously wrong, because it's for
> index only scan it could be true only for heap, not for index pages.

Seems correct to me: if it's an index-only scan, and all pages are
all-visible, then indeed no heap pages will be fetched.

(Note that the cost model doesn't charge anything for touching the
visibility map. This might be too simplistic, but certainly that cost
should be much smaller than touching the heap, since the map is small
enough that it should stay resident in shared buffers.)

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2014-10-27 15:04:15 Re: superuser() shortcuts
Previous Message Teodor Sigaev 2014-10-27 14:54:22 cost_index()