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 765 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().

766 {
767  /*
768  * Free hash table
769  */
770  if (node->hj_HashTable)
771  {
773  node->hj_HashTable = NULL;
774  }
775 
776  /*
777  * Free the exprcontext
778  */
779  ExecFreeExprContext(&node->js.ps);
780 
781  /*
782  * clean out the tuple table
783  */
787 
788  /*
789  * clean up subtrees
790  */
793 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
PlanState ps
Definition: execnodes.h:1840
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:543
TupleTableSlot * hj_OuterTupleSlot
Definition: execnodes.h:1952
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:655
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:983
#define outerPlanState(node)
Definition: execnodes.h:1039
TupleTableSlot * hj_HashTupleSlot
Definition: execnodes.h:1953
HashJoinTable hj_HashTable
Definition: execnodes.h:1947
#define innerPlanState(node)
Definition: execnodes.h:1038
JoinState js
Definition: execnodes.h:1942
void ExecHashTableDestroy(HashJoinTable hashtable)
Definition: nodeHash.c:852

◆ ExecHashJoinEstimate()

void ExecHashJoinEstimate ( HashJoinState state,
ParallelContext pcxt 
)

Definition at line 1437 of file nodeHashjoin.c.

References ParallelContext::estimator, shm_toc_estimate_chunk, and shm_toc_estimate_keys.

Referenced by ExecParallelEstimate().

1438 {
1440  shm_toc_estimate_keys(&pcxt->estimator, 1);
1441 }
shm_toc_estimator estimator
Definition: parallel.h:42
#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 1444 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().

1445 {
1446  int plan_node_id = state->js.ps.plan->plan_node_id;
1447  HashState *hashNode;
1448  ParallelHashJoinState *pstate;
1449 
1450  /*
1451  * Disable shared hash table mode if we failed to create a real DSM
1452  * segment, because that means that we don't have a DSA area to work with.
1453  */
1454  if (pcxt->seg == NULL)
1455  return;
1456 
1458 
1459  /*
1460  * Set up the state needed to coordinate access to the shared hash
1461  * table(s), using the plan node ID as the toc key.
1462  */
1463  pstate = shm_toc_allocate(pcxt->toc, sizeof(ParallelHashJoinState));
1464  shm_toc_insert(pcxt->toc, plan_node_id, pstate);
1465 
1466  /*
1467  * Set up the shared hash join state with no batches initially.
1468  * ExecHashTableCreate() will prepare at least one later and set nbatch
1469  * and space_allowed.
1470  */
1471  pstate->nbatch = 0;
1472  pstate->space_allowed = 0;
1473  pstate->batches = InvalidDsaPointer;
1474  pstate->old_batches = InvalidDsaPointer;
1475  pstate->nbuckets = 0;
1476  pstate->growth = PHJ_GROWTH_OK;
1478  pg_atomic_init_u32(&pstate->distributor, 0);
1479  pstate->nparticipants = pcxt->nworkers + 1;
1480  pstate->total_tuples = 0;
1481  LWLockInitialize(&pstate->lock,
1483  BarrierInit(&pstate->build_barrier, 0);
1484  BarrierInit(&pstate->grow_batches_barrier, 0);
1485  BarrierInit(&pstate->grow_buckets_barrier, 0);
1486 
1487  /* Set up the space we'll use for shared temporary files. */
1488  SharedFileSetInit(&pstate->fileset, pcxt->seg);
1489 
1490  /* Initialize the shared state in the hash node. */
1491  hashNode = (HashState *) innerPlanState(state);
1492  hashNode->parallel_state = pstate;
1493 }
struct ParallelHashJoinState * parallel_state
Definition: execnodes.h:2422
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:49
PlanState ps
Definition: execnodes.h:1840
dsm_segment * seg
Definition: parallel.h:43
int plan_node_id
Definition: plannodes.h:141
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:745
void ExecSetExecProcNode(PlanState *node, ExecProcNodeMtd function)
Definition: execProcnode.c:411
Plan * plan
Definition: execnodes.h:945
ParallelHashGrowth growth
Definition: hashjoin.h:241
dsa_pointer old_batches
Definition: hashjoin.h:237
static TupleTableSlot * ExecParallelHashJoin(PlanState *pstate)
Definition: nodeHashjoin.c:601
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:223
#define innerPlanState(node)
Definition: execnodes.h:1038
JoinState js
Definition: execnodes.h:1942
Barrier grow_batches_barrier
Definition: hashjoin.h:249
shm_toc * toc
Definition: parallel.h:45

◆ ExecHashJoinInitializeWorker()

void ExecHashJoinInitializeWorker ( HashJoinState state,
ParallelWorkerContext pwcxt 
)

Definition at line 1535 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().

1537 {
1538  HashState *hashNode;
1539  int plan_node_id = state->js.ps.plan->plan_node_id;
1540  ParallelHashJoinState *pstate =
1541  shm_toc_lookup(pwcxt->toc, plan_node_id, false);
1542 
1543  /* Attach to the space for shared temporary files. */
1544  SharedFileSetAttach(&pstate->fileset, pwcxt->seg);
1545 
1546  /* Attach to the shared state in the hash node. */
1547  hashNode = (HashState *) innerPlanState(state);
1548  hashNode->parallel_state = pstate;
1549 
1551 }
struct ParallelHashJoinState * parallel_state
Definition: execnodes.h:2422
PlanState ps
Definition: execnodes.h:1840
int plan_node_id
Definition: plannodes.h:141
SharedFileSet fileset
Definition: hashjoin.h:253
void ExecSetExecProcNode(PlanState *node, ExecProcNodeMtd function)
Definition: execProcnode.c:411
Plan * plan
Definition: execnodes.h:945
static TupleTableSlot * ExecParallelHashJoin(PlanState *pstate)
Definition: nodeHashjoin.c:601
void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg)
Definition: sharedfileset.c:78
#define innerPlanState(node)
Definition: execnodes.h:1038
JoinState js
Definition: execnodes.h:1942
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
dsm_segment * seg
Definition: parallel.h:53

◆ ExecHashJoinReInitializeDSM()

void ExecHashJoinReInitializeDSM ( HashJoinState state,
ParallelContext pcxt 
)

Definition at line 1502 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().

1503 {
1504  int plan_node_id = state->js.ps.plan->plan_node_id;
1505  ParallelHashJoinState *pstate =
1506  shm_toc_lookup(cxt->toc, plan_node_id, false);
1507 
1508  /*
1509  * It would be possible to reuse the shared hash table in single-batch
1510  * cases by resetting and then fast-forwarding build_barrier to
1511  * PHJ_BUILD_DONE and batch 0's batch_barrier to PHJ_BATCH_PROBING, but
1512  * currently shared hash tables are already freed by now (by the last
1513  * participant to detach from the batch). We could consider keeping it
1514  * around for single-batch joins. We'd also need to adjust
1515  * finalize_plan() so that it doesn't record a dummy dependency for
1516  * Parallel Hash nodes, preventing the rescan optimization. For now we
1517  * don't try.
1518  */
1519 
1520  /* Detach, freeing any remaining shared memory. */
1521  if (state->hj_HashTable != NULL)
1522  {
1525  }
1526 
1527  /* Clear any shared batch files. */
1528  SharedFileSetDeleteAll(&pstate->fileset);
1529 
1530  /* Reset build_barrier to PHJ_BUILD_ELECTING so we can go around again. */
1531  BarrierInit(&pstate->build_barrier, 0);
1532 }
void BarrierInit(Barrier *barrier, int participants)
Definition: barrier.c:100
PlanState ps
Definition: execnodes.h:1840
void ExecHashTableDetachBatch(HashJoinTable hashtable)
Definition: nodeHash.c:3115
void ExecHashTableDetach(HashJoinTable hashtable)
Definition: nodeHash.c:3172
int plan_node_id
Definition: plannodes.h:141
SharedFileSet fileset
Definition: hashjoin.h:253
Plan * plan
Definition: execnodes.h:945
void SharedFileSetDeleteAll(SharedFileSet *fileset)
HashJoinTable hj_HashTable
Definition: execnodes.h:1947
JoinState js
Definition: execnodes.h:1942
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 1218 of file nodeHashjoin.c.

References BufFileCreateTemp(), BufFileWrite(), and MinimalTupleData::t_len.

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

1220 {
1221  BufFile *file = *fileptr;
1222 
1223  if (file == NULL)
1224  {
1225  /* First write to this batch file, so open it. */
1226  file = BufFileCreateTemp(false);
1227  *fileptr = file;
1228  }
1229 
1230  BufFileWrite(file, (void *) &hashvalue, sizeof(uint32));
1231  BufFileWrite(file, (void *) tuple, tuple->t_len);
1232 }
BufFile * BufFileCreateTemp(bool interXact)
Definition: buffile.c:184
unsigned int uint32
Definition: c.h:367
void BufFileWrite(BufFile *file, void *ptr, size_t size)
Definition: buffile.c:582

◆ ExecInitHashJoin()

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

Definition at line 617 of file nodeHashjoin.c.

References Assert, elog, ERROR, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignProjectionInfo(), ExecGetResultSlotOps(), ExecGetResultType(), ExecHashJoin(), ExecInitExprList(), ExecInitExtraTupleSlot(), ExecInitNode(), ExecInitNullTupleSlot(), ExecInitQual(), ExecInitResultTupleSlotTL(), PlanState::ExecProcNode, HashJoin::hashclauses, HashJoin::hashcollations, HashJoin::hashkeys, HashJoin::hashoperators, 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, makeNode, outerPlan, outerPlanState, Join::plan, PlanState::plan, JoinState::ps, HashState::ps, PlanState::ps_ResultTupleSlot, Plan::qual, PlanState::qual, JoinState::single_match, PlanState::state, and TTSOpsVirtual.

Referenced by ExecInitNode().

618 {
619  HashJoinState *hjstate;
620  Plan *outerNode;
621  Hash *hashNode;
622  TupleDesc outerDesc,
623  innerDesc;
624  const TupleTableSlotOps *ops;
625 
626  /* check for unsupported flags */
627  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
628 
629  /*
630  * create state structure
631  */
632  hjstate = makeNode(HashJoinState);
633  hjstate->js.ps.plan = (Plan *) node;
634  hjstate->js.ps.state = estate;
635 
636  /*
637  * See ExecHashJoinInitializeDSM() and ExecHashJoinInitializeWorker()
638  * where this function may be replaced with a parallel version, if we
639  * managed to launch a parallel query.
640  */
641  hjstate->js.ps.ExecProcNode = ExecHashJoin;
642  hjstate->js.jointype = node->join.jointype;
643 
644  /*
645  * Miscellaneous initialization
646  *
647  * create expression context for node
648  */
649  ExecAssignExprContext(estate, &hjstate->js.ps);
650 
651  /*
652  * initialize child nodes
653  *
654  * Note: we could suppress the REWIND flag for the inner input, which
655  * would amount to betting that the hash will be a single batch. Not
656  * clear if this would be a win or not.
657  */
658  outerNode = outerPlan(node);
659  hashNode = (Hash *) innerPlan(node);
660 
661  outerPlanState(hjstate) = ExecInitNode(outerNode, estate, eflags);
662  outerDesc = ExecGetResultType(outerPlanState(hjstate));
663  innerPlanState(hjstate) = ExecInitNode((Plan *) hashNode, estate, eflags);
664  innerDesc = ExecGetResultType(innerPlanState(hjstate));
665 
666  /*
667  * Initialize result slot, type and projection.
668  */
670  ExecAssignProjectionInfo(&hjstate->js.ps, NULL);
671 
672  /*
673  * tuple table initialization
674  */
675  ops = ExecGetResultSlotOps(outerPlanState(hjstate), NULL);
676  hjstate->hj_OuterTupleSlot = ExecInitExtraTupleSlot(estate, outerDesc,
677  ops);
678 
679  /*
680  * detect whether we need only consider the first matching inner tuple
681  */
682  hjstate->js.single_match = (node->join.inner_unique ||
683  node->join.jointype == JOIN_SEMI);
684 
685  /* set up null tuples for outer joins, if needed */
686  switch (node->join.jointype)
687  {
688  case JOIN_INNER:
689  case JOIN_SEMI:
690  break;
691  case JOIN_LEFT:
692  case JOIN_ANTI:
693  hjstate->hj_NullInnerTupleSlot =
694  ExecInitNullTupleSlot(estate, innerDesc, &TTSOpsVirtual);
695  break;
696  case JOIN_RIGHT:
697  hjstate->hj_NullOuterTupleSlot =
698  ExecInitNullTupleSlot(estate, outerDesc, &TTSOpsVirtual);
699  break;
700  case JOIN_FULL:
701  hjstate->hj_NullOuterTupleSlot =
702  ExecInitNullTupleSlot(estate, outerDesc, &TTSOpsVirtual);
703  hjstate->hj_NullInnerTupleSlot =
704  ExecInitNullTupleSlot(estate, innerDesc, &TTSOpsVirtual);
705  break;
706  default:
707  elog(ERROR, "unrecognized join type: %d",
708  (int) node->join.jointype);
709  }
710 
711  /*
712  * now for some voodoo. our temporary tuple slot is actually the result
713  * tuple slot of the Hash node (which is our inner plan). we can do this
714  * because Hash nodes don't return tuples via ExecProcNode() -- instead
715  * the hash join node uses ExecScanHashBucket() to get at the contents of
716  * the hash table. -cim 6/9/91
717  */
718  {
719  HashState *hashstate = (HashState *) innerPlanState(hjstate);
720  TupleTableSlot *slot = hashstate->ps.ps_ResultTupleSlot;
721 
722  hjstate->hj_HashTupleSlot = slot;
723  }
724 
725  /*
726  * initialize child expressions
727  */
728  hjstate->js.ps.qual =
729  ExecInitQual(node->join.plan.qual, (PlanState *) hjstate);
730  hjstate->js.joinqual =
731  ExecInitQual(node->join.joinqual, (PlanState *) hjstate);
732  hjstate->hashclauses =
733  ExecInitQual(node->hashclauses, (PlanState *) hjstate);
734 
735  /*
736  * initialize hash-specific info
737  */
738  hjstate->hj_HashTable = NULL;
739  hjstate->hj_FirstOuterTupleSlot = NULL;
740 
741  hjstate->hj_CurHashValue = 0;
742  hjstate->hj_CurBucketNo = 0;
744  hjstate->hj_CurTuple = NULL;
745 
746  hjstate->hj_OuterHashKeys = ExecInitExprList(node->hashkeys,
747  (PlanState *) hjstate);
748  hjstate->hj_HashOperators = node->hashoperators;
749  hjstate->hj_Collations = node->hashcollations;
750 
751  hjstate->hj_JoinState = HJ_BUILD_HASHTABLE;
752  hjstate->hj_MatchedOuter = false;
753  hjstate->hj_OuterNotEmpty = false;
754 
755  return hjstate;
756 }
JoinType jointype
Definition: execnodes.h:1841
List * qual
Definition: plannodes.h:143
#define INVALID_SKEW_BUCKET_NO
Definition: hashjoin.h:109
TupleTableSlot * hj_NullInnerTupleSlot
Definition: execnodes.h:1955
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1801
ExprState * joinqual
Definition: execnodes.h:1844
const TupleTableSlotOps * ExecGetResultSlotOps(PlanState *planstate, bool *isfixed)
Definition: execUtils.c:504
List * hashkeys
Definition: plannodes.h:751
PlanState ps
Definition: execnodes.h:1840
List * hashclauses
Definition: plannodes.h:743
bool single_match
Definition: execnodes.h:1842
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
bool hj_MatchedOuter
Definition: execnodes.h:1958
EState * state
Definition: execnodes.h:947
TupleTableSlot * hj_OuterTupleSlot
Definition: execnodes.h:1952
List * hj_OuterHashKeys
Definition: execnodes.h:1944
TupleTableSlot * hj_FirstOuterTupleSlot
Definition: execnodes.h:1956
Join join
Definition: plannodes.h:742
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:209
List * hashcollations
Definition: plannodes.h:745
JoinType jointype
Definition: plannodes.h:684
uint32 hj_CurHashValue
Definition: execnodes.h:1948
int hj_CurSkewBucketNo
Definition: execnodes.h:1950
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:983
#define ERROR
Definition: elog.h:43
TupleTableSlot * hj_NullOuterTupleSlot
Definition: execnodes.h:1954
List * hashoperators
Definition: plannodes.h:744
#define EXEC_FLAG_BACKWARD
Definition: executor.h:58
#define outerPlanState(node)
Definition: execnodes.h:1039
#define innerPlan(node)
Definition: plannodes.h:171
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:540
HashJoinTuple hj_CurTuple
Definition: execnodes.h:1951
List * ExecInitExprList(List *nodes, PlanState *parent)
Definition: execExpr.c:318
PlanState ps
Definition: execnodes.h:2402
List * hj_HashOperators
Definition: execnodes.h:1945
#define outerPlan(node)
Definition: plannodes.h:172
int hj_CurBucketNo
Definition: execnodes.h:1949
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:951
List * hj_Collations
Definition: execnodes.h:1946
Plan * plan
Definition: execnodes.h:945
#define makeNode(_type_)
Definition: nodes.h:577
bool hj_OuterNotEmpty
Definition: execnodes.h:1959
#define Assert(condition)
Definition: c.h:738
#define EXEC_FLAG_MARK
Definition: executor.h:59
TupleTableSlot * ExecInitNullTupleSlot(EState *estate, TupleDesc tupType, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1817
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:485
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1769
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:495
ExprState * qual
Definition: execnodes.h:966
TupleTableSlot * hj_HashTupleSlot
Definition: execnodes.h:1953
#define HJ_BUILD_HASHTABLE
Definition: nodeHashjoin.c:124
HashJoinTable hj_HashTable
Definition: execnodes.h:1947
#define elog(elevel,...)
Definition: elog.h:214
static TupleTableSlot * ExecHashJoin(PlanState *pstate)
Definition: nodeHashjoin.c:585
bool inner_unique
Definition: plannodes.h:685
#define innerPlanState(node)
Definition: execnodes.h:1038
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
JoinState js
Definition: execnodes.h:1942
List * joinqual
Definition: plannodes.h:686
ExprState * hashclauses
Definition: execnodes.h:1943
Plan plan
Definition: plannodes.h:683

◆ ExecReScanHashJoin()

void ExecReScanHashJoin ( HashJoinState node)

Definition at line 1291 of file nodeHashjoin.c.

References Assert, castNode, PlanState::chgParam, ExecHashAccumInstrumentation(), ExecHashTableDestroy(), ExecHashTableResetMatchFlags(), ExecReScan(), HashState::hashtable, HashState::hinstrument, 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, innerPlanState, PlanState::instrument, INVALID_SKEW_BUCKET_NO, HashJoinState::js, PlanState::lefttree, HashJoinTableData::nbatch, palloc0(), JoinState::ps, HashState::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 */
1331  HashState *hashNode = castNode(HashState, innerPlanState(node));
1332 
1333  Assert(hashNode->hashtable == node->hj_HashTable);
1334  /* accumulate stats from old hash table, if wanted */
1335  /* (this should match ExecShutdownHash) */
1336  if (hashNode->ps.instrument && !hashNode->hinstrument)
1337  hashNode->hinstrument = (HashInstrumentation *)
1338  palloc0(sizeof(HashInstrumentation));
1339  if (hashNode->hinstrument)
1341  hashNode->hashtable);
1342  /* for safety, be sure to clear child plan node's pointer too */
1343  hashNode->hashtable = NULL;
1344 
1346  node->hj_HashTable = NULL;
1348 
1349  /*
1350  * if chgParam of subnode is not null then plan will be re-scanned
1351  * by first ExecProcNode.
1352  */
1353  if (node->js.ps.righttree->chgParam == NULL)
1354  ExecReScan(node->js.ps.righttree);
1355  }
1356  }
1357 
1358  /* Always reset intra-tuple state */
1359  node->hj_CurHashValue = 0;
1360  node->hj_CurBucketNo = 0;
1362  node->hj_CurTuple = NULL;
1363 
1364  node->hj_MatchedOuter = false;
1365  node->hj_FirstOuterTupleSlot = NULL;
1366 
1367  /*
1368  * if chgParam of subnode is not null then plan will be re-scanned by
1369  * first ExecProcNode.
1370  */
1371  if (node->js.ps.lefttree->chgParam == NULL)
1372  ExecReScan(node->js.ps.lefttree);
1373 }
#define INVALID_SKEW_BUCKET_NO
Definition: hashjoin.h:109
Instrumentation * instrument
Definition: execnodes.h:955
PlanState ps
Definition: execnodes.h:1840
#define castNode(_type_, nodeptr)
Definition: nodes.h:598
HashJoinTable hashtable
Definition: execnodes.h:2403
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
bool hj_MatchedOuter
Definition: execnodes.h:1958
struct PlanState * righttree
Definition: execnodes.h:968
TupleTableSlot * hj_FirstOuterTupleSlot
Definition: execnodes.h:1956
struct PlanState * lefttree
Definition: execnodes.h:967
#define HJ_FILL_INNER(hjstate)
Definition: nodeHashjoin.c:134
uint32 hj_CurHashValue
Definition: execnodes.h:1948
int hj_CurSkewBucketNo
Definition: execnodes.h:1950
void ExecHashAccumInstrumentation(HashInstrumentation *instrument, HashJoinTable hashtable)
Definition: nodeHash.c:2687
HashJoinTuple hj_CurTuple
Definition: execnodes.h:1951
PlanState ps
Definition: execnodes.h:2402
HashInstrumentation * hinstrument
Definition: execnodes.h:2419
Bitmapset * chgParam
Definition: execnodes.h:977
int hj_CurBucketNo
Definition: execnodes.h:1949
void * palloc0(Size size)
Definition: mcxt.c:980
bool hj_OuterNotEmpty
Definition: execnodes.h:1959
#define Assert(condition)
Definition: c.h:738
#define HJ_NEED_NEW_OUTER
Definition: nodeHashjoin.c:125
#define HJ_BUILD_HASHTABLE
Definition: nodeHashjoin.c:124
HashJoinTable hj_HashTable
Definition: execnodes.h:1947
void ExecHashTableResetMatchFlags(HashJoinTable hashtable)
Definition: nodeHash.c:2166
#define innerPlanState(node)
Definition: execnodes.h:1038
JoinState js
Definition: execnodes.h:1942
void ExecHashTableDestroy(HashJoinTable hashtable)
Definition: nodeHash.c:852

◆ ExecShutdownHashJoin()

void ExecShutdownHashJoin ( HashJoinState node)

Definition at line 1376 of file nodeHashjoin.c.

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

Referenced by ExecShutdownNode().

1377 {
1378  if (node->hj_HashTable)
1379  {
1380  /*
1381  * Detach from shared state before DSM memory goes away. This makes
1382  * sure that we don't have any pointers into DSM memory by the time
1383  * ExecEndHashJoin runs.
1384  */
1387  }
1388 }
void ExecHashTableDetachBatch(HashJoinTable hashtable)
Definition: nodeHash.c:3115
void ExecHashTableDetach(HashJoinTable hashtable)
Definition: nodeHash.c:3172
HashJoinTable hj_HashTable
Definition: execnodes.h:1947