Unix Technical Forum

Re: How to interpret this explain analyse?

This is a discussion on Re: How to interpret this explain analyse? within the Pgsql Performance forums, part of the PostgreSQL category; --> Joost Kraaijeveld wrote: > Hi all, > > A question on how to read and interpret the explain analyse ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Performance

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2008, 11:06 AM
Richard Huxton
 
Posts: n/a
Default Re: How to interpret this explain analyse?

Joost Kraaijeveld wrote:
> Hi all,
>
> A question on how to read and interpret the explain analyse statement
> (and what to do)
>
> I have a query "SELECT A.ordernummer, B.klantnummer FROM orders A
> LEFT OUTER JOIN klt_alg B ON A.Klantnummer=B.Klantnummer ORDER BY
> A.klantnummer;"
>
> Both tables have an btree index on klantnummer (int4, the column the
> join is on). I have vacuumed and analyzed both tables. The explain
> analyse is:


Indexes not necessarily useful here since you're fetching all rows in A
and presumably much of B

Sort
Hash Left Join
Seq Scan on orders a
Hash
Seq Scan on klt_alg b

I've trimmed the above from your explain output. It's sequentially
scanning "b" and using a hash to join to "a" before sorting the results.

> Questions: -> Hash Left Join (cost=41557.43..110069.51 rows=1100836
> width=12) (actual time=21263.858..42845.158 rows=1104380 loops=1)
>
> 0. What exactly are the numbers in "cost=41557.43..110069.51" ( I
> assume for the other questions that 41557.43 is the estimated MS the
> query will take, what are the others)?


The cost numbers represent "effort" rather than time. They're only
really useful in that you can compare one part of the query to another.
There are two numbers because the first shows startup, the second final
time. So - the "outer" parts of the query will have increasing startup
values since the "inner" parts will have to do their work first.

The "actual time" is measured in ms, but remember to multiply it by the
"loops" value. Oh, and actually measuring the time slows the query down too.

> 1. I assume that (cost=41557.43..110069.51 rows=1100836 width=12) is
> the estimated cost and (actual time=21263.858..42845.158 rows=1104380
> loops=1) the actual cost. Is the difference acceptable?
>
> 2. If not, what can I do about it?


The key thing to look for here is the number of rows. If PG expects say
100 rows but there are instead 10,000 then it may choose the wrong plan.
In this case the estimate is 1,100,836 and the actual is 1,104,380 -
very close.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-18-2008, 11:07 AM
Tom Lane
 
Posts: n/a
Default Re: How to interpret this explain analyse?

Richard Huxton <dev@archonet.com> writes:
> Joost Kraaijeveld wrote:
>> 2. If not, what can I do about it?


> The key thing to look for here is the number of rows. If PG expects say
> 100 rows but there are instead 10,000 then it may choose the wrong plan.
> In this case the estimate is 1,100,836 and the actual is 1,104,380 -
> very close.


On the surface this looks like a reasonable plan choice. If you like
you can try the other two basic types of join plan by turning off
enable_hashjoin, which will likely drive the planner to use a merge
join, and then also turn off enable_mergejoin to get a nested loop
(or if it thinks nested loop is second best, turn off enable_nestloop
to see the behavior with a merge join).

What's important in comparing different plan alternatives is the ratios
of estimated costs to actual elapsed times. If the planner is doing its
job well, those ratios should be similar across all the alternatives
(which implies of course that the cheapest-estimate plan is also the
cheapest in reality). If not, it may be appropriate to fool with the
planner's cost estimate parameters to try to line up estimates and
reality a bit better.

See
http://www.postgresql.org/docs/8.0/s...ance-tips.html
for more detail.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:04 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com