Re: seq scan startup cost

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Zeugswetter Andreas SB SD" <ZeugswetterA(at)spardat(dot)at>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: seq scan startup cost
Date: 2002-01-10 15:27:45
Message-ID: 20596.1010676465@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Zeugswetter Andreas SB SD" <ZeugswetterA(at)spardat(dot)at> writes:
> Imho the simplification, that seq scan startup cost is 0.0 is
> only valid when we expect to return most of the rows.

> When expecting only 1 row, imho the costs need to be 50 % for
> startup and 50 % rest.

This is already accounted for in the code that makes use of the
estimates. "Startup cost" is really the time before we can start trying
to produce output, not the time till the first tuple is returned.

An example of the usage is this fragment from costsize.c:

if (subplan->sublink->subLinkType == EXISTS_SUBLINK)
{
/* we only need to fetch 1 tuple */
subcost = plan->startup_cost +
(plan->total_cost - plan->startup_cost) / plan->plan_rows;
}

If a single row is expected, then this will estimate the actual cost to
fetch it as equal to total_cost, not startup_cost.

It's true that for a seqscan we might reasonably hope to find the wanted
row after scanning only half the file, but what of plans like Aggregate?
The startup/total-cost model isn't sufficiently detailed to capture this
difference, so I prefer to stick with the more conservative behavior.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Zeugswetter Andreas SB SD 2002-01-10 16:04:29 Re: again on index usage
Previous Message Tom Lane 2002-01-10 15:07:11 Re: again on index usage