mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
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 straightforward.
This commit is contained in:
@@ -889,8 +889,8 @@ generate_join_implied_equalities_normal(PlannerInfo *root,
|
||||
* combination for which an opfamily member operator exists. If we have
|
||||
* choices, we prefer simple Var members (possibly with RelabelType) since
|
||||
* these are (a) cheapest to compute at runtime and (b) most likely to
|
||||
* have useful statistics. Also, if enable_hashjoin is on, we prefer
|
||||
* operators that are also hashjoinable.
|
||||
* have useful statistics. Also, prefer operators that are also
|
||||
* hashjoinable.
|
||||
*/
|
||||
if (outer_members && inner_members)
|
||||
{
|
||||
@@ -925,8 +925,7 @@ generate_join_implied_equalities_normal(PlannerInfo *root,
|
||||
(IsA(inner_em->em_expr, RelabelType) &&
|
||||
IsA(((RelabelType *) inner_em->em_expr)->arg, Var)))
|
||||
score++;
|
||||
if (!enable_hashjoin ||
|
||||
op_hashjoinable(eq_op,
|
||||
if (op_hashjoinable(eq_op,
|
||||
exprType((Node *) outer_em->em_expr)))
|
||||
score++;
|
||||
if (score > best_score)
|
||||
|
||||
Reference in New Issue
Block a user