pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: srobertjames <srobertjames@gmail.com>
To: pgsql-performance <pgsql-performance@postgresql.org>
Subject: Re: Understanding Hash Join performance
Date: Thu, 02 Jun 2011 09:57:25 -0500
Message-ID: <4DE75E85020000250003DFEB@gw.wicourts.gov> (raw)
In-Reply-To: <BANLkTikh3k=TcezOUk86k6CFw39oF6=uGA@mail.gmail.com>
References: <BANLkTikh3k=TcezOUk86k6CFw39oF6=uGA@mail.gmail.com>

Robert James <srobertjames@gmail.com> wrote:
 
> A query I has spends a long time on Hash Joins (and Hash Left
> Joins).
 
To submit a post which gives us enough information to help you speed
up that query, please read this page:
 
http://wiki.postgresql.org/wiki/SlowQueryQuestions
 
> I have a few questions:
> 
> 1. When does Postgres decide to do a Hash Join, over another type
>    of Join?
> 2. Do Hash Joins normally perform poorly?  What can I do to speed
>    them up?
> 3. What can I do to enable Postgres to use a faster type of join?
 
Questions this general can only be answered in a general way, so
here goes.
 
The planner doesn't choose a particular plan type, exactly -- it
generates a lot of alternative plans,, basically looking at all the
ways it knows how to retrieve the requested set of data, and
estimates a cost for each plan based on available resources and
adjustable costing factors.  It will choose the plan with the lowest
estimated cost. There are many situations where a hash join is
faster than the alternatives.  If it's using one where another
alternative is actually faster, it's not a matter of "enabling a
faster join type" -- it's a matter of setting your cost factors to
accurately reflect the real costs on your system.
 
You can generally make hash joins faster by increasing work_mem, but
that tends to cause data to be pushed from cache sooner and can run
you out of memory entirely, so it must be tuned carefully.  And the
planner does take the size of work_mem and the expected data set
into consideration when estimating the cost of the hash join.
 
-Kevin



view thread (5+ messages)  latest in thread

Message-ID: <4DE75E85020000250003DFEB@gw.wicourts.gov>
Permalink:  ../4DE75E85020000250003DFEB@gw.wicourts.gov/
Also on:    postgresql.org/message-id/4DE75E85020000250003DFEB@gw.wicourts.gov

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: Kevin.Grittner@wicourts.gov, srobertjames@gmail.com
  Subject: Re: Understanding Hash Join performance
  In-Reply-To: <4DE75E85020000250003DFEB@gw.wicourts.gov>
  References: <BANLkTikh3k=TcezOUk86k6CFw39oF6=uGA@mail.gmail.com> <4DE75E85020000250003DFEB@gw.wicourts.gov>

* 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