pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Dunstan <andrew@dunslane.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Thomas Kellerer <spam_eater@gmx.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: query optimization
Date: Thu, 26 Apr 2012 16:27:38 -0400
Message-ID: <4F99AFBA.4090605@dunslane.net> (raw)
In-Reply-To: <13222.1335470935@sss.pgh.pa.us>
References: <alpine.DEB.2.02.1204241008570.9591@krichy.tvnetwork.hu>
	<12228.1335467838@sss.pgh.pa.us>
	<jnc860$q30$1@dough.gmane.org>
	<13222.1335470935@sss.pgh.pa.us>



On 04/26/2012 04:08 PM, Tom Lane wrote:
> Thomas Kellerer<spam_eater@gmx.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



view thread (22+ messages)  latest in thread

Message-ID: <4F99AFBA.4090605@dunslane.net>
Permalink:  ../4F99AFBA.4090605@dunslane.net/
Also on:    postgresql.org/message-id/4F99AFBA.4090605@dunslane.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: andrew@dunslane.net, tgl@sss.pgh.pa.us, spam_eater@gmx.net
  Subject: Re: query optimization
  In-Reply-To: <4F99AFBA.4090605@dunslane.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox