Re: how to identify expensive steps in an explain analyze output

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Frits Hoogland" <frits(dot)hoogland(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: how to identify expensive steps in an explain analyze output
Date: 2008-02-27 15:26:07
Message-ID: 28433.1204125967@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

"Frits Hoogland" <frits(dot)hoogland(at)gmail(dot)com> writes:
> The manual states: "Actually two numbers are shown: the start-up time before
> the first row can be returned, and the total time to return all the rows.".
> Does this mean that the difference between the first and second is the cost
> or the time the step in the explain has taken?

No, or at least only for a very strange definition of "cost". An
example of the way these are used is that for a hash join, the startup
time would include the time needed to scan the inner relation and build
the hash table from it. The run time (ie, difference between startup
and total) represents the part of the process where we're scanning the
outer relation and probing into the hash table for matches. Rows are
returned as matches are found during this part of the process. I can't
think of any useful definition under which the startup time would be
ignored.

The reason the planner divides the total cost like this is that in the
presence of LIMIT or a few other SQL features, it may not be necessary
to run the plan to completion, but only to fetch the first few rows.
In this case a plan with low startup cost may be preferred, even though
the estimated total cost to run it to completion might be higher than
some other plan has. We're not *going* to run it to completion, and
so the really interesting figure is startup cost plus some appropriate
fraction of run cost. You can see this at work if you look at the
EXPLAIN numbers for a query involving a LIMIT.

The whole thing might make a bit more sense if you read
http://www.postgresql.org/docs/8.3/static/overview.html
particularly the last two subsections.

regards, tom lane

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Douglas J Hunley 2008-02-27 16:01:57 questions about CLUSTER
Previous Message Frits Hoogland 2008-02-27 11:54:01 how to identify expensive steps in an explain analyze output