Re: How to change order sort of table in HashJoin - Mailing list pgsql-hackers

From Tom Lane
Subject Re: How to change order sort of table in HashJoin
Date
Msg-id 21633.1479572313@sss.pgh.pa.us
Whole thread Raw
In response to How to change order sort of table in HashJoin  (Man Trieu <man.trieu@gmail.com>)
Responses Re: How to change order sort of table in HashJoin  (Man <man.trieu@gmail.com>)
List pgsql-hackers
Man Trieu <man.trieu@gmail.com> writes:
> As in the example below, i think the plan which hash table is created on
> testtbl2 (the fewer tuples) should be choosen.

The planner usually prefers to hash on the table that has a flatter
MCV histogram, since a hash table with many key collisions will be
inefficient.  You might find it illuminating to read the comments around
estimate_hash_bucketsize().

In general, given a hashtable that fits in memory and light bucket
loading, a hash join is more or less O(M) + O(N); it doesn't matter
so much whether the larger table is on the inside.  It does matter if
the table gets big enough to force batching of the join, but that's
not happening in your example (at least not the first one; it's unclear
to me why it did happen in the second one).  The key thing that will
drive the choice, then, is avoiding a skewed bucket distribution that
causes lots of comparisons for common values.

            regards, tom lane


pgsql-hackers by date:

Previous
From: "Karl O. Pinc"
Date:
Subject: Re: Patch to implement pg_current_logfile() function
Next
From: "Joshua D. Drake"
Date:
Subject: Re: Mail thread references in commits