Skip site navigation (1) Skip section navigation (2)

pgsql: Support RIGHT and FULL OUTER JOIN in hash joins.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Support RIGHT and FULL OUTER JOIN in hash joins.
Date: 2010-12-31 01:26:31
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-committers
Support RIGHT and FULL OUTER JOIN in hash joins.

This is advantageous first because it allows us to hash the smaller table
regardless of the outer-join type, and second because hash join can be more
flexible than merge join in dealing with arbitrary join quals in a FULL
join.  For merge join all the join quals have to be mergejoinable, but hash
join will work so long as there's at least one hashjoinable qual --- the
others can be any condition.  (This is true essentially because we don't
keep per-inner-tuple match flags in merge join, while hash join can do so.)

To do this, we need a has-it-been-matched flag for each tuple in the
hashtable, not just one for the current outer tuple.  The key idea that
makes this practical is that we can store the match flag in the tuple's
infomask, since there are lots of bits there that are of no interest for a
MinimalTuple.  So we aren't increasing the size of the hashtable at all for
the feature.

To write this without turning the hash code into even more of a pile of
spaghetti than it already was, I rewrote ExecHashJoin in a state-machine
style, similar to ExecMergeJoin.  Other than that decision, it was pretty



Modified Files
src/backend/executor/nodeHash.c         |  151 ++++++++-
src/backend/executor/nodeHashjoin.c     |  576 ++++++++++++++++++-------------
src/backend/optimizer/path/equivclass.c |    7 +-
src/backend/optimizer/path/joinpath.c   |  145 +++-----
src/backend/optimizer/path/joinrels.c   |   12 +
src/backend/optimizer/plan/initsplan.c  |   10 +-
src/include/access/htup.h               |   23 ++
src/include/executor/hashjoin.h         |    2 +
src/include/executor/nodeHash.h         |   10 +-
src/include/nodes/execnodes.h           |   23 +-
10 files changed, 596 insertions(+), 363 deletions(-)


pgsql-committers by date

Next:From: Robert HaasDate: 2010-12-31 02:02:01
Subject: Re: pgsql: Support RIGHT and FULL OUTER JOIN in hash joins.
Previous:From: Peter EisentrautDate: 2010-12-30 20:16:15
Subject: pgsql: Remove tabs in SGML

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group