PostgreSQL Source Code  git master
nodeHashjoin.h File Reference
#include "access/parallel.h"
#include "nodes/execnodes.h"
#include "storage/buffile.h"
Include dependency graph for nodeHashjoin.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

HashJoinStateExecInitHashJoin (HashJoin *node, EState *estate, int eflags)
 
void ExecEndHashJoin (HashJoinState *node)
 
void ExecReScanHashJoin (HashJoinState *node)
 
void ExecShutdownHashJoin (HashJoinState *node)
 
void ExecHashJoinEstimate (HashJoinState *state, ParallelContext *pcxt)
 
void ExecHashJoinInitializeDSM (HashJoinState *state, ParallelContext *pcxt)
 
void ExecHashJoinReInitializeDSM (HashJoinState *state, ParallelContext *pcxt)
 
void ExecHashJoinInitializeWorker (HashJoinState *state, ParallelWorkerContext *pwcxt)
 
void ExecHashJoinSaveTuple (MinimalTuple tuple, uint32 hashvalue, BufFile **fileptr)
 

Function Documentation

◆ ExecEndHashJoin()

void ExecEndHashJoin ( HashJoinState node)

Definition at line 760 of file nodeHashjoin.c.

References ExecClearTuple(), ExecEndNode(), ExecFreeExprContext(), ExecHashTableDestroy(), HashJoinState::hj_HashTable, HashJoinState::hj_HashTupleSlot, HashJoinState::hj_OuterTupleSlot, innerPlanState, HashJoinState::js, outerPlanState, JoinState::ps, and PlanState::ps_ResultTupleSlot.

Referenced by ExecEndNode().

761 {
762  /*
763  * Free hash table
764  */
765  if (node->hj_HashTable)
766  {
768  node->hj_HashTable = NULL;
769  }
770 
771  /*
772  * Free the exprcontext
773  */
774  ExecFreeExprContext(&node->js.ps);
775 
776  /*
777  * clean out the tuple table
778  */
782 
783  /*
784  * clean up subtrees
785  */
788 }
PlanState ps
Definition: execnodes.h:1687
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:538
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:475
TupleTableSlot * hj_OuterTupleSlot
Definition: execnodes.h:1800
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:566
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:946
#define outerPlanState(node)
Definition: execnodes.h:966
TupleTableSlot * hj_HashTupleSlot
Definition: execnodes.h:1801
HashJoinTable hj_HashTable
Definition: execnodes.h:1795
#define innerPlanState(node)
Definition: execnodes.h:965
JoinState js
Definition: execnodes.h:1790
void ExecHashTableDestroy(HashJoinTable hashtable)
Definition: nodeHash.c:849

◆ ExecHashJoinEstimate()

void ExecHashJoinEstimate ( HashJoinState state,
ParallelContext pcxt 
)

Definition at line 1418 of file nodeHashjoin.c.

References ParallelContext::estimator, shm_toc_estimate_chunk, and shm_toc_estimate_keys.

Referenced by ExecParallelEstimate().

1419 {
1421  shm_toc_estimate_keys(&pcxt->estimator, 1);
1422 }
shm_toc_estimator estimator
Definition: parallel.h:41
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53

◆ ExecHashJoinInitializeDSM()

void ExecHashJoinInitializeDSM ( HashJoinState state,
ParallelContext pcxt 
)

Definition at line 1425 of file nodeHashjoin.c.

References BarrierInit(), ParallelHashJoinState::batches, ParallelHashJoinState::build_barrier, ParallelHashJoinState::chunk_work_queue, ParallelHashJoinState::distributor, ExecParallelHashJoin(), ExecSetExecProcNode(), ParallelHashJoinState::fileset, ParallelHashJoinState::grow_batches_barrier, ParallelHashJoinState::grow_buckets_barrier, ParallelHashJoinState::growth, innerPlanState, InvalidDsaPointer, HashJoinState::js, ParallelHashJoinState::lock, LWLockInitialize(), LWTRANCHE_PARALLEL_HASH_JOIN, ParallelHashJoinState::nbatch, ParallelHashJoinState::nbuckets, ParallelHashJoinState::nparticipants, ParallelContext::nworkers, ParallelHashJoinState::old_batches, HashState::parallel_state, pg_atomic_init_u32(), PHJ_GROWTH_OK, PlanState::plan, Plan::plan_node_id, JoinState::ps, ParallelContext::seg, SharedFileSetInit(), shm_toc_allocate(), shm_toc_insert(), ParallelHashJoinState::space_allowed, ParallelContext::toc, and ParallelHashJoinState::total_tuples.

Referenced by ExecParallelInitializeDSM().

1426 {
1427  int plan_node_id = state->js.ps.plan->plan_node_id;
1428  HashState *hashNode;
1429  ParallelHashJoinState *pstate;
1430 
1431  /*
1432  * Disable shared hash table mode if we failed to create a real DSM
1433  * segment, because that means that we don't have a DSA area to work with.
1434  */
1435  if (pcxt->seg == NULL)
1436  return;
1437 
1439 
1440  /*
1441  * Set up the state needed to coordinate access to the shared hash
1442  * table(s), using the plan node ID as the toc key.
1443  */
1444  pstate = shm_toc_allocate(pcxt->toc, sizeof(ParallelHashJoinState));
1445  shm_toc_insert(pcxt->toc, plan_node_id, pstate);
1446 
1447  /*
1448  * Set up the shared hash join state with no batches initially.
1449  * ExecHashTableCreate() will prepare at least one later and set nbatch
1450  * and space_allowed.
1451  */
1452  pstate->nbatch = 0;
1453  pstate->space_allowed = 0;
1454  pstate->batches = InvalidDsaPointer;
1455  pstate->old_batches = InvalidDsaPointer;
1456  pstate->nbuckets = 0;
1457  pstate->growth = PHJ_GROWTH_OK;
1459  pg_atomic_init_u32(&pstate->distributor, 0);
1460  pstate->nparticipants = pcxt->nworkers + 1;
1461  pstate->total_tuples = 0;
1462  LWLockInitialize(&pstate->lock,
1464  BarrierInit(&pstate->build_barrier, 0);
1465  BarrierInit(&pstate->grow_batches_barrier, 0);
1466  BarrierInit(&pstate->grow_buckets_barrier, 0);
1467 
1468  /* Set up the space we'll use for shared temporary files. */
1469  SharedFileSetInit(&pstate->fileset, pcxt->seg);
1470 
1471  /* Initialize the shared state in the hash node. */
1472  hashNode = (HashState *) innerPlanState(state);
1473  hashNode->parallel_state = pstate;
1474 }
struct ParallelHashJoinState * parallel_state
Definition: execnodes.h:2137
dsa_pointer chunk_work_queue
Definition: hashjoin.h:242
#define InvalidDsaPointer
Definition: dsa.h:78
void BarrierInit(Barrier *barrier, int participants)
Definition: barrier.c:100
void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg)
Definition: sharedfileset.c:47
PlanState ps
Definition: execnodes.h:1687
dsm_segment * seg
Definition: parallel.h:42
int plan_node_id
Definition: plannodes.h:146
SharedFileSet fileset
Definition: hashjoin.h:253
Barrier grow_buckets_barrier
Definition: hashjoin.h:250
dsa_pointer batches
Definition: hashjoin.h:236
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition: lwlock.c:677
void ExecSetExecProcNode(PlanState *node, ExecProcNodeMtd function)
Definition: execProcnode.c:406
Plan * plan
Definition: execnodes.h:912
ParallelHashGrowth growth
Definition: hashjoin.h:241
dsa_pointer old_batches
Definition: hashjoin.h:237
static TupleTableSlot * ExecParallelHashJoin(PlanState *pstate)
Definition: nodeHashjoin.c:575
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
pg_atomic_uint32 distributor
Definition: hashjoin.h:251
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:226
#define innerPlanState(node)
Definition: execnodes.h:965
JoinState js
Definition: execnodes.h:1790
Barrier grow_batches_barrier
Definition: hashjoin.h:249
shm_toc * toc
Definition: parallel.h:44

◆ ExecHashJoinInitializeWorker()

void ExecHashJoinInitializeWorker ( HashJoinState state,
ParallelWorkerContext pwcxt 
)

Definition at line 1516 of file nodeHashjoin.c.

References ExecParallelHashJoin(), ExecSetExecProcNode(), ParallelHashJoinState::fileset, innerPlanState, HashJoinState::js, HashState::parallel_state, PlanState::plan, Plan::plan_node_id, JoinState::ps, ParallelWorkerContext::seg, SharedFileSetAttach(), shm_toc_lookup(), and ParallelWorkerContext::toc.

Referenced by ExecParallelInitializeWorker().

1518 {
1519  HashState *hashNode;
1520  int plan_node_id = state->js.ps.plan->plan_node_id;
1521  ParallelHashJoinState *pstate =
1522  shm_toc_lookup(pwcxt->toc, plan_node_id, false);
1523 
1524  /* Attach to the space for shared temporary files. */
1525  SharedFileSetAttach(&pstate->fileset, pwcxt->seg);
1526 
1527  /* Attach to the shared state in the hash node. */
1528  hashNode = (HashState *) innerPlanState(state);
1529  hashNode->parallel_state = pstate;
1530 
1532 }
struct ParallelHashJoinState * parallel_state
Definition: execnodes.h:2137
PlanState ps
Definition: execnodes.h:1687
int plan_node_id
Definition: plannodes.h:146
SharedFileSet fileset
Definition: hashjoin.h:253
void ExecSetExecProcNode(PlanState *node, ExecProcNodeMtd function)
Definition: execProcnode.c:406
Plan * plan
Definition: execnodes.h:912
static TupleTableSlot * ExecParallelHashJoin(PlanState *pstate)
Definition: nodeHashjoin.c:575
void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg)
Definition: sharedfileset.c:76
#define innerPlanState(node)
Definition: execnodes.h:965
JoinState js
Definition: execnodes.h:1790
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
dsm_segment * seg
Definition: parallel.h:52

◆ ExecHashJoinReInitializeDSM()

void ExecHashJoinReInitializeDSM ( HashJoinState state,
ParallelContext pcxt 
)

Definition at line 1483 of file nodeHashjoin.c.

References BarrierInit(), ParallelHashJoinState::build_barrier, ExecHashTableDetach(), ExecHashTableDetachBatch(), ParallelHashJoinState::fileset, HashJoinState::hj_HashTable, HashJoinState::js, PlanState::plan, Plan::plan_node_id, JoinState::ps, SharedFileSetDeleteAll(), shm_toc_lookup(), and ParallelContext::toc.

Referenced by ExecParallelReInitializeDSM().

1484 {
1485  int plan_node_id = state->js.ps.plan->plan_node_id;
1486  ParallelHashJoinState *pstate =
1487  shm_toc_lookup(cxt->toc, plan_node_id, false);
1488 
1489  /*
1490  * It would be possible to reuse the shared hash table in single-batch
1491  * cases by resetting and then fast-forwarding build_barrier to
1492  * PHJ_BUILD_DONE and batch 0's batch_barrier to PHJ_BATCH_PROBING, but
1493  * currently shared hash tables are already freed by now (by the last
1494  * participant to detach from the batch). We could consider keeping it
1495  * around for single-batch joins. We'd also need to adjust
1496  * finalize_plan() so that it doesn't record a dummy dependency for
1497  * Parallel Hash nodes, preventing the rescan optimization. For now we
1498  * don't try.
1499  */
1500 
1501  /* Detach, freeing any remaining shared memory. */
1502  if (state->hj_HashTable != NULL)
1503  {
1506  }
1507 
1508  /* Clear any shared batch files. */
1509  SharedFileSetDeleteAll(&pstate->fileset);
1510 
1511  /* Reset build_barrier to PHJ_BUILD_ELECTING so we can go around again. */
1512  BarrierInit(&pstate->build_barrier, 0);
1513 }
void BarrierInit(Barrier *barrier, int participants)
Definition: barrier.c:100
PlanState ps
Definition: execnodes.h:1687
void ExecHashTableDetachBatch(HashJoinTable hashtable)
Definition: nodeHash.c:3059
void ExecHashTableDetach(HashJoinTable hashtable)
Definition: nodeHash.c:3116
int plan_node_id
Definition: plannodes.h:146
SharedFileSet fileset
Definition: hashjoin.h:253
Plan * plan
Definition: execnodes.h:912
void SharedFileSetDeleteAll(SharedFileSet *fileset)
HashJoinTable hj_HashTable
Definition: execnodes.h:1795
JoinState js
Definition: execnodes.h:1790
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232

◆ ExecHashJoinSaveTuple()

void ExecHashJoinSaveTuple ( MinimalTuple  tuple,
uint32  hashvalue,
BufFile **  fileptr 
)

Definition at line 1211 of file nodeHashjoin.c.

References BufFileCreateTemp(), BufFileWrite(), ereport, errcode_for_file_access(), errmsg(), ERROR, and MinimalTupleData::t_len.

Referenced by ExecHashIncreaseNumBatches(), ExecHashJoinImpl(), ExecHashRemoveNextSkewBucket(), and ExecHashTableInsert().

1213 {
1214  BufFile *file = *fileptr;
1215  size_t written;
1216 
1217  if (file == NULL)
1218  {
1219  /* First write to this batch file, so open it. */
1220  file = BufFileCreateTemp(false);
1221  *fileptr = file;
1222  }
1223 
1224  written = BufFileWrite(file, (void *) &hashvalue, sizeof(uint32));
1225  if (written != sizeof(uint32))
1226  ereport(ERROR,
1228  errmsg("could not write to hash-join temporary file: %m")));
1229 
1230  written = BufFileWrite(file, (void *) tuple, tuple->t_len);
1231  if (written != tuple->t_len)
1232  ereport(ERROR,
1234  errmsg("could not write to hash-join temporary file: %m")));
1235 }
#define ERROR
Definition: elog.h:43
BufFile * BufFileCreateTemp(bool interXact)
Definition: buffile.c:193
int errcode_for_file_access(void)
Definition: elog.c:598
unsigned int uint32
Definition: c.h:325
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
size_t BufFileWrite(BufFile *file, void *ptr, size_t size)
Definition: buffile.c:592

◆ ExecInitHashJoin()

HashJoinState* ExecInitHashJoin ( HashJoin node,
EState estate,
int  eflags 
)

Definition at line 591 of file nodeHashjoin.c.

References OpExpr::args, Assert, elog, ERROR, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignProjectionInfo(), ExecGetResultType(), ExecHashJoin(), ExecInitExpr(), ExecInitExtraTupleSlot(), ExecInitNode(), ExecInitNullTupleSlot(), ExecInitQual(), ExecInitResultTupleSlotTL(), PlanState::ExecProcNode, HashJoin::hashclauses, HJ_BUILD_HASHTABLE, HashJoinState::hj_HashTupleSlot, HashJoinState::hj_NullInnerTupleSlot, HashJoinState::hj_NullOuterTupleSlot, HashJoinState::hj_OuterTupleSlot, Join::inner_unique, innerPlan, innerPlanState, INVALID_SKEW_BUCKET_NO, HashJoin::join, JOIN_ANTI, JOIN_FULL, JOIN_INNER, JOIN_LEFT, JOIN_RIGHT, JOIN_SEMI, Join::joinqual, Join::jointype, JoinState::jointype, HashJoinState::js, lappend(), lappend_oid(), lfirst_node, linitial, lsecond, makeNode, NIL, OpExpr::opno, outerPlan, outerPlanState, Join::plan, PlanState::plan, JoinState::ps, HashState::ps, PlanState::ps_ResultTupleSlot, Plan::qual, PlanState::qual, JoinState::single_match, and PlanState::state.

Referenced by ExecInitNode().

592 {
593  HashJoinState *hjstate;
594  Plan *outerNode;
595  Hash *hashNode;
596  List *lclauses;
597  List *rclauses;
598  List *hoperators;
599  TupleDesc outerDesc,
600  innerDesc;
601  ListCell *l;
602 
603  /* check for unsupported flags */
604  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
605 
606  /*
607  * create state structure
608  */
609  hjstate = makeNode(HashJoinState);
610  hjstate->js.ps.plan = (Plan *) node;
611  hjstate->js.ps.state = estate;
612 
613  /*
614  * See ExecHashJoinInitializeDSM() and ExecHashJoinInitializeWorker()
615  * where this function may be replaced with a parallel version, if we
616  * managed to launch a parallel query.
617  */
618  hjstate->js.ps.ExecProcNode = ExecHashJoin;
619  hjstate->js.jointype = node->join.jointype;
620 
621  /*
622  * Miscellaneous initialization
623  *
624  * create expression context for node
625  */
626  ExecAssignExprContext(estate, &hjstate->js.ps);
627 
628  /*
629  * initialize child nodes
630  *
631  * Note: we could suppress the REWIND flag for the inner input, which
632  * would amount to betting that the hash will be a single batch. Not
633  * clear if this would be a win or not.
634  */
635  outerNode = outerPlan(node);
636  hashNode = (Hash *) innerPlan(node);
637 
638  outerPlanState(hjstate) = ExecInitNode(outerNode, estate, eflags);
639  outerDesc = ExecGetResultType(outerPlanState(hjstate));
640  innerPlanState(hjstate) = ExecInitNode((Plan *) hashNode, estate, eflags);
641  innerDesc = ExecGetResultType(innerPlanState(hjstate));
642 
643  /*
644  * Initialize result slot, type and projection.
645  */
646  ExecInitResultTupleSlotTL(estate, &hjstate->js.ps);
647  ExecAssignProjectionInfo(&hjstate->js.ps, NULL);
648 
649  /*
650  * tuple table initialization
651  */
652  hjstate->hj_OuterTupleSlot = ExecInitExtraTupleSlot(estate, outerDesc);
653 
654  /*
655  * detect whether we need only consider the first matching inner tuple
656  */
657  hjstate->js.single_match = (node->join.inner_unique ||
658  node->join.jointype == JOIN_SEMI);
659 
660  /* set up null tuples for outer joins, if needed */
661  switch (node->join.jointype)
662  {
663  case JOIN_INNER:
664  case JOIN_SEMI:
665  break;
666  case JOIN_LEFT:
667  case JOIN_ANTI:
668  hjstate->hj_NullInnerTupleSlot =
669  ExecInitNullTupleSlot(estate, innerDesc);
670  break;
671  case JOIN_RIGHT:
672  hjstate->hj_NullOuterTupleSlot =
673  ExecInitNullTupleSlot(estate, outerDesc);
674  break;
675  case JOIN_FULL:
676  hjstate->hj_NullOuterTupleSlot =
677  ExecInitNullTupleSlot(estate, outerDesc);
678  hjstate->hj_NullInnerTupleSlot =
679  ExecInitNullTupleSlot(estate, innerDesc);
680  break;
681  default:
682  elog(ERROR, "unrecognized join type: %d",
683  (int) node->join.jointype);
684  }
685 
686  /*
687  * now for some voodoo. our temporary tuple slot is actually the result
688  * tuple slot of the Hash node (which is our inner plan). we can do this
689  * because Hash nodes don't return tuples via ExecProcNode() -- instead
690  * the hash join node uses ExecScanHashBucket() to get at the contents of
691  * the hash table. -cim 6/9/91
692  */
693  {
694  HashState *hashstate = (HashState *) innerPlanState(hjstate);
695  TupleTableSlot *slot = hashstate->ps.ps_ResultTupleSlot;
696 
697  hjstate->hj_HashTupleSlot = slot;
698  }
699 
700  /*
701  * initialize child expressions
702  */
703  hjstate->js.ps.qual =
704  ExecInitQual(node->join.plan.qual, (PlanState *) hjstate);
705  hjstate->js.joinqual =
706  ExecInitQual(node->join.joinqual, (PlanState *) hjstate);
707  hjstate->hashclauses =
708  ExecInitQual(node->hashclauses, (PlanState *) hjstate);
709 
710  /*
711  * initialize hash-specific info
712  */
713  hjstate->hj_HashTable = NULL;
714  hjstate->hj_FirstOuterTupleSlot = NULL;
715 
716  hjstate->hj_CurHashValue = 0;
717  hjstate->hj_CurBucketNo = 0;
719  hjstate->hj_CurTuple = NULL;
720 
721  /*
722  * Deconstruct the hash clauses into outer and inner argument values, so
723  * that we can evaluate those subexpressions separately. Also make a list
724  * of the hash operator OIDs, in preparation for looking up the hash
725  * functions to use.
726  */
727  lclauses = NIL;
728  rclauses = NIL;
729  hoperators = NIL;
730  foreach(l, node->hashclauses)
731  {
732  OpExpr *hclause = lfirst_node(OpExpr, l);
733 
734  lclauses = lappend(lclauses, ExecInitExpr(linitial(hclause->args),
735  (PlanState *) hjstate));
736  rclauses = lappend(rclauses, ExecInitExpr(lsecond(hclause->args),
737  (PlanState *) hjstate));
738  hoperators = lappend_oid(hoperators, hclause->opno);
739  }
740  hjstate->hj_OuterHashKeys = lclauses;
741  hjstate->hj_InnerHashKeys = rclauses;
742  hjstate->hj_HashOperators = hoperators;
743  /* child Hash node needs to evaluate inner hash keys, too */
744  ((HashState *) innerPlanState(hjstate))->hashkeys = rclauses;
745 
746  hjstate->hj_JoinState = HJ_BUILD_HASHTABLE;
747  hjstate->hj_MatchedOuter = false;
748  hjstate->hj_OuterNotEmpty = false;
749 
750  return hjstate;
751 }
JoinType jointype
Definition: execnodes.h:1688
#define NIL
Definition: pg_list.h:69
List * qual
Definition: plannodes.h:148
#define INVALID_SKEW_BUCKET_NO
Definition: hashjoin.h:109
TupleTableSlot * hj_NullInnerTupleSlot
Definition: execnodes.h:1803
ExprState * joinqual
Definition: execnodes.h:1691
PlanState ps
Definition: execnodes.h:1687
List * hashclauses
Definition: plannodes.h:740
bool single_match
Definition: execnodes.h:1689
bool hj_MatchedOuter
Definition: execnodes.h:1806
EState * state
Definition: execnodes.h:914
TupleTableSlot * hj_OuterTupleSlot
Definition: execnodes.h:1800
List * hj_OuterHashKeys
Definition: execnodes.h:1792
List * lappend_oid(List *list, Oid datum)
Definition: list.c:164
TupleTableSlot * hj_FirstOuterTupleSlot
Definition: execnodes.h:1804
#define lsecond(l)
Definition: pg_list.h:116
Join join
Definition: plannodes.h:739
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc)
Definition: execTuples.c:931
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:205
JoinType jointype
Definition: plannodes.h:681
uint32 hj_CurHashValue
Definition: execnodes.h:1796
int hj_CurSkewBucketNo
Definition: execnodes.h:1798
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:946
TupleTableSlot * ExecInitNullTupleSlot(EState *estate, TupleDesc tupType)
Definition: execTuples.c:945
#define linitial(l)
Definition: pg_list.h:111
#define ERROR
Definition: elog.h:43
TupleTableSlot * hj_NullOuterTupleSlot
Definition: execnodes.h:1802
#define EXEC_FLAG_BACKWARD
Definition: executor.h:60
#define lfirst_node(type, lc)
Definition: pg_list.h:109
#define outerPlanState(node)
Definition: execnodes.h:966
#define innerPlan(node)
Definition: plannodes.h:176
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:456
HashJoinTuple hj_CurTuple
Definition: execnodes.h:1799
PlanState ps
Definition: execnodes.h:2128
List * hj_HashOperators
Definition: execnodes.h:1794
#define outerPlan(node)
Definition: plannodes.h:177
List * lappend(List *list, void *datum)
Definition: list.c:128
int hj_CurBucketNo
Definition: execnodes.h:1797
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:918
void ExecInitResultTupleSlotTL(EState *estate, PlanState *planstate)
Definition: execTuples.c:890
Plan * plan
Definition: execnodes.h:912
#define makeNode(_type_)
Definition: nodes.h:564
bool hj_OuterNotEmpty
Definition: execnodes.h:1807
#define Assert(condition)
Definition: c.h:699
#define EXEC_FLAG_MARK
Definition: executor.h:61
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:428
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:438
ExprState * qual
Definition: execnodes.h:930
TupleTableSlot * hj_HashTupleSlot
Definition: execnodes.h:1801
List * hj_InnerHashKeys
Definition: execnodes.h:1793
#define HJ_BUILD_HASHTABLE
Definition: nodeHashjoin.c:124
HashJoinTable hj_HashTable
Definition: execnodes.h:1795
static TupleTableSlot * ExecHashJoin(PlanState *pstate)
Definition: nodeHashjoin.c:559
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:119
Oid opno
Definition: primnodes.h:496
#define elog
Definition: elog.h:219
bool inner_unique
Definition: plannodes.h:682
List * args
Definition: primnodes.h:502
#define innerPlanState(node)
Definition: execnodes.h:965
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
Definition: pg_list.h:45
JoinState js
Definition: execnodes.h:1790
List * joinqual
Definition: plannodes.h:683
ExprState * hashclauses
Definition: execnodes.h:1791
Plan plan
Definition: plannodes.h:680

◆ ExecReScanHashJoin()

void ExecReScanHashJoin ( HashJoinState node)

Definition at line 1291 of file nodeHashjoin.c.

References PlanState::chgParam, ExecHashTableDestroy(), ExecHashTableResetMatchFlags(), ExecReScan(), HJ_BUILD_HASHTABLE, HashJoinState::hj_CurBucketNo, HashJoinState::hj_CurHashValue, HashJoinState::hj_CurSkewBucketNo, HashJoinState::hj_CurTuple, HJ_FILL_INNER, HashJoinState::hj_FirstOuterTupleSlot, HashJoinState::hj_HashTable, HashJoinState::hj_JoinState, HashJoinState::hj_MatchedOuter, HJ_NEED_NEW_OUTER, HashJoinState::hj_OuterNotEmpty, INVALID_SKEW_BUCKET_NO, HashJoinState::js, PlanState::lefttree, HashJoinTableData::nbatch, JoinState::ps, and PlanState::righttree.

Referenced by ExecReScan().

1292 {
1293  /*
1294  * In a multi-batch join, we currently have to do rescans the hard way,
1295  * primarily because batch temp files may have already been released. But
1296  * if it's a single-batch join, and there is no parameter change for the
1297  * inner subnode, then we can just re-use the existing hash table without
1298  * rebuilding it.
1299  */
1300  if (node->hj_HashTable != NULL)
1301  {
1302  if (node->hj_HashTable->nbatch == 1 &&
1303  node->js.ps.righttree->chgParam == NULL)
1304  {
1305  /*
1306  * Okay to reuse the hash table; needn't rescan inner, either.
1307  *
1308  * However, if it's a right/full join, we'd better reset the
1309  * inner-tuple match flags contained in the table.
1310  */
1311  if (HJ_FILL_INNER(node))
1313 
1314  /*
1315  * Also, we need to reset our state about the emptiness of the
1316  * outer relation, so that the new scan of the outer will update
1317  * it correctly if it turns out to be empty this time. (There's no
1318  * harm in clearing it now because ExecHashJoin won't need the
1319  * info. In the other cases, where the hash table doesn't exist
1320  * or we are destroying it, we leave this state alone because
1321  * ExecHashJoin will need it the first time through.)
1322  */
1323  node->hj_OuterNotEmpty = false;
1324 
1325  /* ExecHashJoin can skip the BUILD_HASHTABLE step */
1327  }
1328  else
1329  {
1330  /* must destroy and rebuild hash table */
1332  node->hj_HashTable = NULL;
1334 
1335  /*
1336  * if chgParam of subnode is not null then plan will be re-scanned
1337  * by first ExecProcNode.
1338  */
1339  if (node->js.ps.righttree->chgParam == NULL)
1340  ExecReScan(node->js.ps.righttree);
1341  }
1342  }
1343 
1344  /* Always reset intra-tuple state */
1345  node->hj_CurHashValue = 0;
1346  node->hj_CurBucketNo = 0;
1348  node->hj_CurTuple = NULL;
1349 
1350  node->hj_MatchedOuter = false;
1351  node->hj_FirstOuterTupleSlot = NULL;
1352 
1353  /*
1354  * if chgParam of subnode is not null then plan will be re-scanned by
1355  * first ExecProcNode.
1356  */
1357  if (node->js.ps.lefttree->chgParam == NULL)
1358  ExecReScan(node->js.ps.lefttree);
1359 }
#define INVALID_SKEW_BUCKET_NO
Definition: hashjoin.h:109
PlanState ps
Definition: execnodes.h:1687
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
bool hj_MatchedOuter
Definition: execnodes.h:1806
struct PlanState * righttree
Definition: execnodes.h:932
TupleTableSlot * hj_FirstOuterTupleSlot
Definition: execnodes.h:1804
struct PlanState * lefttree
Definition: execnodes.h:931
#define HJ_FILL_INNER(hjstate)
Definition: nodeHashjoin.c:134
uint32 hj_CurHashValue
Definition: execnodes.h:1796
int hj_CurSkewBucketNo
Definition: execnodes.h:1798
HashJoinTuple hj_CurTuple
Definition: execnodes.h:1799
Bitmapset * chgParam
Definition: execnodes.h:941
int hj_CurBucketNo
Definition: execnodes.h:1797
bool hj_OuterNotEmpty
Definition: execnodes.h:1807
#define HJ_NEED_NEW_OUTER
Definition: nodeHashjoin.c:125
#define HJ_BUILD_HASHTABLE
Definition: nodeHashjoin.c:124
HashJoinTable hj_HashTable
Definition: execnodes.h:1795
void ExecHashTableResetMatchFlags(HashJoinTable hashtable)
Definition: nodeHash.c:2143
JoinState js
Definition: execnodes.h:1790
void ExecHashTableDestroy(HashJoinTable hashtable)
Definition: nodeHash.c:849

◆ ExecShutdownHashJoin()

void ExecShutdownHashJoin ( HashJoinState node)

Definition at line 1362 of file nodeHashjoin.c.

References ExecHashTableDetach(), ExecHashTableDetachBatch(), and HashJoinState::hj_HashTable.

Referenced by ExecShutdownNode().

1363 {
1364  if (node->hj_HashTable)
1365  {
1366  /*
1367  * Detach from shared state before DSM memory goes away. This makes
1368  * sure that we don't have any pointers into DSM memory by the time
1369  * ExecEndHashJoin runs.
1370  */
1373  }
1374 }
void ExecHashTableDetachBatch(HashJoinTable hashtable)
Definition: nodeHash.c:3059
void ExecHashTableDetach(HashJoinTable hashtable)
Definition: nodeHash.c:3116
HashJoinTable hj_HashTable
Definition: execnodes.h:1795