From: Tom Lane <tgl@sss.pgh.pa.us>
To: Scott Carey <scott@richrelevance.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: pgsql-performance@postgresql.org Performance <pgsql-performance@postgresql.org>
Subject: Re: HashJoin order, hash the large or small table? Postgres likes to hash the big one, why?
Date: Wed, 13 Apr 2011 13:35:31 -0400
Message-ID: <8747.1302716131@sss.pgh.pa.us> (raw)
In-Reply-To: <C9CB28BE.306C0%scott@richrelevance.com>
References: <C9CB28BE.306C0%scott@richrelevance.com>
Scott Carey <scott@richrelevance.com> writes:
>> On Oct 27, 2010, at 12:56 PM, Tom Lane wrote:
>> Because a poorly distributed inner relation leads to long hash chains.
>> In the very worst case, all the keys are on the same hash chain and it
>> degenerates to a nested-loop join.
> A pathological skew case (all relations with the same key), should be
> _cheaper_ to probe.
I think you're missing the point, which is that all the hash work is
just pure overhead in such a case (and it is most definitely not
zero-cost overhead). You might as well just do a nestloop join.
Hashing is only beneficial to the extent that it allows a smaller subset
of the inner relation to be compared to each outer-relation tuple.
So I think biasing against skew-distributed inner relations is entirely
appropriate.
regards, tom lane
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: tgl@sss.pgh.pa.us, scott@richrelevance.com, robertmhaas@gmail.com
Subject: Re: HashJoin order, hash the large or small table? Postgres likes to hash the big one, why?
In-Reply-To: <8747.1302716131@sss.pgh.pa.us>
* 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