Skip site navigation (1) Skip section navigation (2)

Re: query optimization

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Thomas Kellerer <spam_eater(at)gmx(dot)net>, pgsql-performance(at)postgresql(dot)org
Subject: Re: query optimization
Date: 2012-04-26 20:27:38
Message-ID: 4F99AFBA.4090605@dunslane.net (view raw or flat)
Thread:
Lists: pgsql-performance

On 04/26/2012 04:08 PM, Tom Lane wrote:
> Thomas Kellerer<spam_eater(at)gmx(dot)net>  writes:
>> Tom Lane wrote on 26.04.2012 21:17:
>>> Um ... did you analyze all the tables, or just some of them?  I get
>>> sub-millisecond runtimes if all four tables have been analyzed, but it
>>> does seem to pick lousy plans if, say, only a and b have been analyzed.
>> Here it's similar to Richard's experience:
>> Before analyzing the four tables, the first statement yields this plan:
>> [ merge joins ]
>> This continues to stay the plan for about 10-15 repetitions, then it turns to this plan
>> [ hash joins ]
> Hmm.  I see it liking the merge-join plan (with minor variations) with
> or without analyze data, but if just some of the tables have been
> analyzed, it goes for the hash plan which is a good deal slower.  The
> cost estimates aren't that far apart though.  In any case, the only
> reason the merge join is so fast is that the data is perfectly ordered
> in each table; on a less contrived example, it could well be a lot
> slower.
>

It's not so terribly contrived, is it? It's common enough to have tables 
which are append-only and to join them by something that corresponds to 
the append order (serial field, timestamp etc.)

cheers

andrew

In response to

pgsql-performance by date

Next:From: Tom LaneDate: 2012-04-26 20:58:20
Subject: Re: Weird plan variation with recursive CTEs
Previous:From: Kevin GrittnerDate: 2012-04-26 20:11:07
Subject: Re: auto-vacuum vs. full table update

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group