Re: Hash join and picking which result set to build the hash table with. - Mailing list pgsql-general

From Tom Lane
Subject Re: Hash join and picking which result set to build the hash table with.
Date
Msg-id 14387.1716411233@sss.pgh.pa.us
Whole thread Raw
In response to Hash join and picking which result set to build the hash table with.  ("Dirschel, Steve" <steve.dirschel@thomsonreuters.com>)
List pgsql-general
"Dirschel, Steve" <steve.dirschel@thomsonreuters.com> writes:
> The query and execution plan are shown below.  My question is
> related to the result set the optimizer is choosing to build the
> hash table from.  My understanding is for a hash join you want to
> build the hash table out of the smaller result set.

That's *a* consideration, but not the only one.  We also consider
whether the hash key has a flat distribution; if it is too skewed,
we might find specific hash chains getting too long.

> When running some tests I forgot to create the PK on table
> docloc_test.  When the PK was not on the table the optimizer decided
> to create the hash table off the 1000 rows from collection.  But as
> soon as I put the PK on that table it then decides to use
> docloc_test to build the hash table.

I think that the presence of a unique index overrides the statistics
(or the lack of any) so that the planner knows that the column is
unique and thus safe to use as a hash key.  Now, it should have
known that anyway, unless maybe this is a freshly-built table that
auto-analyze hasn't gotten to yet?

            regards, tom lane



pgsql-general by date:

Previous
From: "Dirschel, Steve"
Date:
Subject: Hash join and picking which result set to build the hash table with.
Next
From: sud
Date:
Subject: Long running query causing XID limit breach