Re: HashJoin order, hash the large or small table? Postgres likes to hash the big one, why? - Mailing list pgsql-performance

From Tom Lane
Subject Re: HashJoin order, hash the large or small table? Postgres likes to hash the big one, why?
Date
Msg-id 8747.1302716131@sss.pgh.pa.us
Whole thread Raw
In response to Re: HashJoin order, hash the large or small table? Postgres likes to hash the big one, why?  (Scott Carey <scott@richrelevance.com>)
Responses Re: HashJoin order, hash the large or small table? Postgres likes to hash the big one, why?
List pgsql-performance
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

pgsql-performance by date:

Previous
From: Scott Carey
Date:
Subject: Re: HashJoin order, hash the large or small table? Postgres likes to hash the big one, why?
Next
From: Scott Carey
Date:
Subject: Re: HashJoin order, hash the large or small table? Postgres likes to hash the big one, why?