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, HashJoinTable hashtable)
 

Function Documentation

◆ ExecEndHashJoin()

void ExecEndHashJoin ( HashJoinState node)

Definition at line 859 of file nodeHashjoin.c.

860 {
861  /*
862  * Free hash table
863  */
864  if (node->hj_HashTable)
865  {
867  node->hj_HashTable = NULL;
868  }
869 
870  /*
871  * Free the exprcontext
872  */
873  ExecFreeExprContext(&node->js.ps);
874 
875  /*
876  * clean out the tuple table
877  */
881 
882  /*
883  * clean up subtrees
884  */
887 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:557
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:658
#define outerPlanState(node)
Definition: execnodes.h:1133
#define innerPlanState(node)
Definition: execnodes.h:1132
void ExecHashTableDestroy(HashJoinTable hashtable)
Definition: nodeHash.c:889
TupleTableSlot * hj_OuterTupleSlot
Definition: execnodes.h:2115
JoinState js
Definition: execnodes.h:2105
HashJoinTable hj_HashTable
Definition: execnodes.h:2110
TupleTableSlot * hj_HashTupleSlot
Definition: execnodes.h:2116
PlanState ps
Definition: execnodes.h:2002
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1075
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:432

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

◆ ExecHashJoinEstimate()

void ExecHashJoinEstimate ( HashJoinState state,
ParallelContext pcxt 
)

Definition at line 1556 of file nodeHashjoin.c.

1557 {
1559  shm_toc_estimate_keys(&pcxt->estimator, 1);
1560 }
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
shm_toc_estimator estimator
Definition: parallel.h:42

References ParallelContext::estimator, shm_toc_estimate_chunk, and shm_toc_estimate_keys.

Referenced by ExecParallelEstimate().

◆ ExecHashJoinInitializeDSM()

void ExecHashJoinInitializeDSM ( HashJoinState state,
ParallelContext pcxt 
)

Definition at line 1563 of file nodeHashjoin.c.

1564 {
1565  int plan_node_id = state->js.ps.plan->plan_node_id;
1566  HashState *hashNode;
1567  ParallelHashJoinState *pstate;
1568 
1569  /*
1570  * Disable shared hash table mode if we failed to create a real DSM
1571  * segment, because that means that we don't have a DSA area to work with.
1572  */
1573  if (pcxt->seg == NULL)
1574  return;
1575 
1577 
1578  /*
1579  * Set up the state needed to coordinate access to the shared hash
1580  * table(s), using the plan node ID as the toc key.
1581  */
1582  pstate = shm_toc_allocate(pcxt->toc, sizeof(ParallelHashJoinState));
1583  shm_toc_insert(pcxt->toc, plan_node_id, pstate);
1584 
1585  /*
1586  * Set up the shared hash join state with no batches initially.
1587  * ExecHashTableCreate() will prepare at least one later and set nbatch
1588  * and space_allowed.
1589  */
1590  pstate->nbatch = 0;
1591  pstate->space_allowed = 0;
1592  pstate->batches = InvalidDsaPointer;
1593  pstate->old_batches = InvalidDsaPointer;
1594  pstate->nbuckets = 0;
1595  pstate->growth = PHJ_GROWTH_OK;
1597  pg_atomic_init_u32(&pstate->distributor, 0);
1598  pstate->nparticipants = pcxt->nworkers + 1;
1599  pstate->total_tuples = 0;
1600  LWLockInitialize(&pstate->lock,
1602  BarrierInit(&pstate->build_barrier, 0);
1603  BarrierInit(&pstate->grow_batches_barrier, 0);
1604  BarrierInit(&pstate->grow_buckets_barrier, 0);
1605 
1606  /* Set up the space we'll use for shared temporary files. */
1607  SharedFileSetInit(&pstate->fileset, pcxt->seg);
1608 
1609  /* Initialize the shared state in the hash node. */
1610  hashNode = (HashState *) innerPlanState(state);
1611  hashNode->parallel_state = pstate;
1612 }
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
Definition: atomics.h:218
void BarrierInit(Barrier *barrier, int participants)
Definition: barrier.c:100
#define InvalidDsaPointer
Definition: dsa.h:78
void ExecSetExecProcNode(PlanState *node, ExecProcNodeMtd function)
Definition: execProcnode.c:425
@ PHJ_GROWTH_OK
Definition: hashjoin.h:233
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition: lwlock.c:730
@ LWTRANCHE_PARALLEL_HASH_JOIN
Definition: lwlock.h:196
static TupleTableSlot * ExecParallelHashJoin(PlanState *pstate)
Definition: nodeHashjoin.c:694
void SharedFileSetInit(SharedFileSet *fileset, dsm_segment *seg)
Definition: sharedfileset.c:44
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
struct ParallelHashJoinState * parallel_state
Definition: execnodes.h:2681
dsm_segment * seg
Definition: parallel.h:43
shm_toc * toc
Definition: parallel.h:45
Barrier grow_batches_barrier
Definition: hashjoin.h:261
dsa_pointer old_batches
Definition: hashjoin.h:249
dsa_pointer chunk_work_queue
Definition: hashjoin.h:254
Barrier grow_buckets_barrier
Definition: hashjoin.h:262
ParallelHashGrowth growth
Definition: hashjoin.h:253
pg_atomic_uint32 distributor
Definition: hashjoin.h:263
SharedFileSet fileset
Definition: hashjoin.h:265
dsa_pointer batches
Definition: hashjoin.h:248
Definition: regguts.h:323

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, 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, ParallelContext::seg, SharedFileSetInit(), shm_toc_allocate(), shm_toc_insert(), ParallelHashJoinState::space_allowed, ParallelContext::toc, and ParallelHashJoinState::total_tuples.

Referenced by ExecParallelInitializeDSM().

◆ ExecHashJoinInitializeWorker()

void ExecHashJoinInitializeWorker ( HashJoinState state,
ParallelWorkerContext pwcxt 
)

Definition at line 1654 of file nodeHashjoin.c.

1656 {
1657  HashState *hashNode;
1658  int plan_node_id = state->js.ps.plan->plan_node_id;
1659  ParallelHashJoinState *pstate =
1660  shm_toc_lookup(pwcxt->toc, plan_node_id, false);
1661 
1662  /* Attach to the space for shared temporary files. */
1663  SharedFileSetAttach(&pstate->fileset, pwcxt->seg);
1664 
1665  /* Attach to the shared state in the hash node. */
1666  hashNode = (HashState *) innerPlanState(state);
1667  hashNode->parallel_state = pstate;
1668 
1670 }
void SharedFileSetAttach(SharedFileSet *fileset, dsm_segment *seg)
Definition: sharedfileset.c:62
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
dsm_segment * seg
Definition: parallel.h:53

References ExecParallelHashJoin(), ExecSetExecProcNode(), ParallelHashJoinState::fileset, innerPlanState, HashState::parallel_state, ParallelWorkerContext::seg, SharedFileSetAttach(), shm_toc_lookup(), and ParallelWorkerContext::toc.

Referenced by ExecParallelInitializeWorker().

◆ ExecHashJoinReInitializeDSM()

void ExecHashJoinReInitializeDSM ( HashJoinState state,
ParallelContext pcxt 
)

Definition at line 1621 of file nodeHashjoin.c.

1622 {
1623  int plan_node_id = state->js.ps.plan->plan_node_id;
1624  ParallelHashJoinState *pstate =
1625  shm_toc_lookup(pcxt->toc, plan_node_id, false);
1626 
1627  /*
1628  * It would be possible to reuse the shared hash table in single-batch
1629  * cases by resetting and then fast-forwarding build_barrier to
1630  * PHJ_BUILD_FREE and batch 0's batch_barrier to PHJ_BATCH_PROBE, but
1631  * currently shared hash tables are already freed by now (by the last
1632  * participant to detach from the batch). We could consider keeping it
1633  * around for single-batch joins. We'd also need to adjust
1634  * finalize_plan() so that it doesn't record a dummy dependency for
1635  * Parallel Hash nodes, preventing the rescan optimization. For now we
1636  * don't try.
1637  */
1638 
1639  /* Detach, freeing any remaining shared memory. */
1640  if (state->hj_HashTable != NULL)
1641  {
1642  ExecHashTableDetachBatch(state->hj_HashTable);
1643  ExecHashTableDetach(state->hj_HashTable);
1644  }
1645 
1646  /* Clear any shared batch files. */
1647  SharedFileSetDeleteAll(&pstate->fileset);
1648 
1649  /* Reset build_barrier to PHJ_BUILD_ELECT so we can go around again. */
1650  BarrierInit(&pstate->build_barrier, 0);
1651 }
void ExecHashTableDetachBatch(HashJoinTable hashtable)
Definition: nodeHash.c:3279
void ExecHashTableDetach(HashJoinTable hashtable)
Definition: nodeHash.c:3371
void SharedFileSetDeleteAll(SharedFileSet *fileset)
Definition: sharedfileset.c:89

References BarrierInit(), ParallelHashJoinState::build_barrier, ExecHashTableDetach(), ExecHashTableDetachBatch(), ParallelHashJoinState::fileset, SharedFileSetDeleteAll(), shm_toc_lookup(), and ParallelContext::toc.

Referenced by ExecParallelReInitializeDSM().

◆ ExecHashJoinSaveTuple()

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

Definition at line 1327 of file nodeHashjoin.c.

1329 {
1330  BufFile *file = *fileptr;
1331 
1332  /*
1333  * The batch file is lazily created. If this is the first tuple written to
1334  * this batch, the batch file is created and its buffer is allocated in
1335  * the spillCxt context, NOT in the batchCxt.
1336  *
1337  * During the build phase, buffered files are created for inner batches.
1338  * Each batch's buffered file is closed (and its buffer freed) after the
1339  * batch is loaded into memory during the outer side scan. Therefore, it
1340  * is necessary to allocate the batch file buffer in a memory context
1341  * which outlives the batch itself.
1342  *
1343  * Also, we use spillCxt instead of hashCxt for a better accounting of the
1344  * spilling memory consumption.
1345  */
1346  if (file == NULL)
1347  {
1348  MemoryContext oldctx = MemoryContextSwitchTo(hashtable->spillCxt);
1349 
1350  file = BufFileCreateTemp(false);
1351  *fileptr = file;
1352 
1353  MemoryContextSwitchTo(oldctx);
1354  }
1355 
1356  BufFileWrite(file, &hashvalue, sizeof(uint32));
1357  BufFileWrite(file, tuple, tuple->t_len);
1358 }
BufFile * BufFileCreateTemp(bool interXact)
Definition: buffile.c:193
void BufFileWrite(BufFile *file, const void *ptr, size_t size)
Definition: buffile.c:676
unsigned int uint32
Definition: c.h:495
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
MemoryContext spillCxt
Definition: hashjoin.h:364

References BufFileCreateTemp(), BufFileWrite(), MemoryContextSwitchTo(), HashJoinTableData::spillCxt, and MinimalTupleData::t_len.

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

◆ ExecInitHashJoin()

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

Definition at line 710 of file nodeHashjoin.c.

711 {
712  HashJoinState *hjstate;
713  Plan *outerNode;
714  Hash *hashNode;
715  TupleDesc outerDesc,
716  innerDesc;
717  const TupleTableSlotOps *ops;
718 
719  /* check for unsupported flags */
720  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
721 
722  /*
723  * create state structure
724  */
725  hjstate = makeNode(HashJoinState);
726  hjstate->js.ps.plan = (Plan *) node;
727  hjstate->js.ps.state = estate;
728 
729  /*
730  * See ExecHashJoinInitializeDSM() and ExecHashJoinInitializeWorker()
731  * where this function may be replaced with a parallel version, if we
732  * managed to launch a parallel query.
733  */
734  hjstate->js.ps.ExecProcNode = ExecHashJoin;
735  hjstate->js.jointype = node->join.jointype;
736 
737  /*
738  * Miscellaneous initialization
739  *
740  * create expression context for node
741  */
742  ExecAssignExprContext(estate, &hjstate->js.ps);
743 
744  /*
745  * initialize child nodes
746  *
747  * Note: we could suppress the REWIND flag for the inner input, which
748  * would amount to betting that the hash will be a single batch. Not
749  * clear if this would be a win or not.
750  */
751  outerNode = outerPlan(node);
752  hashNode = (Hash *) innerPlan(node);
753 
754  outerPlanState(hjstate) = ExecInitNode(outerNode, estate, eflags);
755  outerDesc = ExecGetResultType(outerPlanState(hjstate));
756  innerPlanState(hjstate) = ExecInitNode((Plan *) hashNode, estate, eflags);
757  innerDesc = ExecGetResultType(innerPlanState(hjstate));
758 
759  /*
760  * Initialize result slot, type and projection.
761  */
763  ExecAssignProjectionInfo(&hjstate->js.ps, NULL);
764 
765  /*
766  * tuple table initialization
767  */
768  ops = ExecGetResultSlotOps(outerPlanState(hjstate), NULL);
769  hjstate->hj_OuterTupleSlot = ExecInitExtraTupleSlot(estate, outerDesc,
770  ops);
771 
772  /*
773  * detect whether we need only consider the first matching inner tuple
774  */
775  hjstate->js.single_match = (node->join.inner_unique ||
776  node->join.jointype == JOIN_SEMI);
777 
778  /* set up null tuples for outer joins, if needed */
779  switch (node->join.jointype)
780  {
781  case JOIN_INNER:
782  case JOIN_SEMI:
783  break;
784  case JOIN_LEFT:
785  case JOIN_ANTI:
786  hjstate->hj_NullInnerTupleSlot =
787  ExecInitNullTupleSlot(estate, innerDesc, &TTSOpsVirtual);
788  break;
789  case JOIN_RIGHT:
790  case JOIN_RIGHT_ANTI:
791  hjstate->hj_NullOuterTupleSlot =
792  ExecInitNullTupleSlot(estate, outerDesc, &TTSOpsVirtual);
793  break;
794  case JOIN_FULL:
795  hjstate->hj_NullOuterTupleSlot =
796  ExecInitNullTupleSlot(estate, outerDesc, &TTSOpsVirtual);
797  hjstate->hj_NullInnerTupleSlot =
798  ExecInitNullTupleSlot(estate, innerDesc, &TTSOpsVirtual);
799  break;
800  default:
801  elog(ERROR, "unrecognized join type: %d",
802  (int) node->join.jointype);
803  }
804 
805  /*
806  * now for some voodoo. our temporary tuple slot is actually the result
807  * tuple slot of the Hash node (which is our inner plan). we can do this
808  * because Hash nodes don't return tuples via ExecProcNode() -- instead
809  * the hash join node uses ExecScanHashBucket() to get at the contents of
810  * the hash table. -cim 6/9/91
811  */
812  {
813  HashState *hashstate = (HashState *) innerPlanState(hjstate);
814  TupleTableSlot *slot = hashstate->ps.ps_ResultTupleSlot;
815 
816  hjstate->hj_HashTupleSlot = slot;
817  }
818 
819  /*
820  * initialize child expressions
821  */
822  hjstate->js.ps.qual =
823  ExecInitQual(node->join.plan.qual, (PlanState *) hjstate);
824  hjstate->js.joinqual =
825  ExecInitQual(node->join.joinqual, (PlanState *) hjstate);
826  hjstate->hashclauses =
827  ExecInitQual(node->hashclauses, (PlanState *) hjstate);
828 
829  /*
830  * initialize hash-specific info
831  */
832  hjstate->hj_HashTable = NULL;
833  hjstate->hj_FirstOuterTupleSlot = NULL;
834 
835  hjstate->hj_CurHashValue = 0;
836  hjstate->hj_CurBucketNo = 0;
838  hjstate->hj_CurTuple = NULL;
839 
840  hjstate->hj_OuterHashKeys = ExecInitExprList(node->hashkeys,
841  (PlanState *) hjstate);
842  hjstate->hj_HashOperators = node->hashoperators;
843  hjstate->hj_Collations = node->hashcollations;
844 
845  hjstate->hj_JoinState = HJ_BUILD_HASHTABLE;
846  hjstate->hj_MatchedOuter = false;
847  hjstate->hj_OuterNotEmpty = false;
848 
849  return hjstate;
850 }
#define ERROR
Definition: elog.h:39
List * ExecInitExprList(List *nodes, PlanState *parent)
Definition: execExpr.c:323
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:214
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
TupleTableSlot * ExecInitNullTupleSlot(EState *estate, TupleDesc tupType, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1848
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1832
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1800
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:498
const TupleTableSlotOps * ExecGetResultSlotOps(PlanState *planstate, bool *isfixed)
Definition: execUtils.c:507
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:488
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:543
#define EXEC_FLAG_BACKWARD
Definition: executor.h:68
#define EXEC_FLAG_MARK
Definition: executor.h:69
#define INVALID_SKEW_BUCKET_NO
Definition: hashjoin.h:120
Assert(fmt[strlen(fmt) - 1] !='\n')
static TupleTableSlot * ExecHashJoin(PlanState *pstate)
Definition: nodeHashjoin.c:678
#define HJ_BUILD_HASHTABLE
Definition: nodeHashjoin.c:180
#define makeNode(_type_)
Definition: nodes.h:176
@ JOIN_SEMI
Definition: nodes.h:318
@ JOIN_FULL
Definition: nodes.h:306
@ JOIN_INNER
Definition: nodes.h:304
@ JOIN_RIGHT
Definition: nodes.h:307
@ JOIN_LEFT
Definition: nodes.h:305
@ JOIN_RIGHT_ANTI
Definition: nodes.h:320
@ JOIN_ANTI
Definition: nodes.h:319
#define innerPlan(node)
Definition: plannodes.h:182
#define outerPlan(node)
Definition: plannodes.h:183
HashJoinTuple hj_CurTuple
Definition: execnodes.h:2114
int hj_CurSkewBucketNo
Definition: execnodes.h:2113
List * hj_OuterHashKeys
Definition: execnodes.h:2107
TupleTableSlot * hj_NullOuterTupleSlot
Definition: execnodes.h:2117
bool hj_OuterNotEmpty
Definition: execnodes.h:2122
TupleTableSlot * hj_NullInnerTupleSlot
Definition: execnodes.h:2118
List * hj_HashOperators
Definition: execnodes.h:2108
ExprState * hashclauses
Definition: execnodes.h:2106
TupleTableSlot * hj_FirstOuterTupleSlot
Definition: execnodes.h:2119
bool hj_MatchedOuter
Definition: execnodes.h:2121
uint32 hj_CurHashValue
Definition: execnodes.h:2111
List * hj_Collations
Definition: execnodes.h:2109
int hj_CurBucketNo
Definition: execnodes.h:2112
List * hashcollations
Definition: plannodes.h:865
List * hashclauses
Definition: plannodes.h:863
List * hashoperators
Definition: plannodes.h:864
Join join
Definition: plannodes.h:862
List * hashkeys
Definition: plannodes.h:871
PlanState ps
Definition: execnodes.h:2661
JoinType jointype
Definition: execnodes.h:2003
ExprState * joinqual
Definition: execnodes.h:2006
bool single_match
Definition: execnodes.h:2004
List * joinqual
Definition: plannodes.h:791
JoinType jointype
Definition: plannodes.h:789
bool inner_unique
Definition: plannodes.h:790
ExprState * qual
Definition: execnodes.h:1058
Plan * plan
Definition: execnodes.h:1037
EState * state
Definition: execnodes.h:1039
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1043

References Assert(), elog(), ERROR, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignProjectionInfo(), ExecGetResultSlotOps(), ExecGetResultType(), ExecHashJoin(), ExecInitExprList(), ExecInitExtraTupleSlot(), ExecInitNode(), ExecInitNullTupleSlot(), ExecInitQual(), ExecInitResultTupleSlotTL(), PlanState::ExecProcNode, HashJoinState::hashclauses, HashJoin::hashclauses, HashJoin::hashcollations, HashJoin::hashkeys, HashJoin::hashoperators, HJ_BUILD_HASHTABLE, HashJoinState::hj_Collations, HashJoinState::hj_CurBucketNo, HashJoinState::hj_CurHashValue, HashJoinState::hj_CurSkewBucketNo, HashJoinState::hj_CurTuple, HashJoinState::hj_FirstOuterTupleSlot, HashJoinState::hj_HashOperators, HashJoinState::hj_HashTable, HashJoinState::hj_HashTupleSlot, HashJoinState::hj_JoinState, HashJoinState::hj_MatchedOuter, HashJoinState::hj_NullInnerTupleSlot, HashJoinState::hj_NullOuterTupleSlot, HashJoinState::hj_OuterHashKeys, HashJoinState::hj_OuterNotEmpty, 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_RIGHT_ANTI, JOIN_SEMI, JoinState::joinqual, Join::joinqual, JoinState::jointype, Join::jointype, HashJoinState::js, makeNode, outerPlan, outerPlanState, PlanState::plan, JoinState::ps, HashState::ps, PlanState::ps_ResultTupleSlot, PlanState::qual, JoinState::single_match, PlanState::state, and TTSOpsVirtual.

Referenced by ExecInitNode().

◆ ExecReScanHashJoin()

void ExecReScanHashJoin ( HashJoinState node)

Definition at line 1407 of file nodeHashjoin.c.

1408 {
1411 
1412  /*
1413  * In a multi-batch join, we currently have to do rescans the hard way,
1414  * primarily because batch temp files may have already been released. But
1415  * if it's a single-batch join, and there is no parameter change for the
1416  * inner subnode, then we can just re-use the existing hash table without
1417  * rebuilding it.
1418  */
1419  if (node->hj_HashTable != NULL)
1420  {
1421  if (node->hj_HashTable->nbatch == 1 &&
1422  innerPlan->chgParam == NULL)
1423  {
1424  /*
1425  * Okay to reuse the hash table; needn't rescan inner, either.
1426  *
1427  * However, if it's a right/right-anti/full join, we'd better
1428  * reset the inner-tuple match flags contained in the table.
1429  */
1430  if (HJ_FILL_INNER(node))
1432 
1433  /*
1434  * Also, we need to reset our state about the emptiness of the
1435  * outer relation, so that the new scan of the outer will update
1436  * it correctly if it turns out to be empty this time. (There's no
1437  * harm in clearing it now because ExecHashJoin won't need the
1438  * info. In the other cases, where the hash table doesn't exist
1439  * or we are destroying it, we leave this state alone because
1440  * ExecHashJoin will need it the first time through.)
1441  */
1442  node->hj_OuterNotEmpty = false;
1443 
1444  /* ExecHashJoin can skip the BUILD_HASHTABLE step */
1446  }
1447  else
1448  {
1449  /* must destroy and rebuild hash table */
1450  HashState *hashNode = castNode(HashState, innerPlan);
1451 
1452  Assert(hashNode->hashtable == node->hj_HashTable);
1453  /* accumulate stats from old hash table, if wanted */
1454  /* (this should match ExecShutdownHash) */
1455  if (hashNode->ps.instrument && !hashNode->hinstrument)
1456  hashNode->hinstrument = (HashInstrumentation *)
1457  palloc0(sizeof(HashInstrumentation));
1458  if (hashNode->hinstrument)
1460  hashNode->hashtable);
1461  /* for safety, be sure to clear child plan node's pointer too */
1462  hashNode->hashtable = NULL;
1463 
1465  node->hj_HashTable = NULL;
1467 
1468  /*
1469  * if chgParam of subnode is not null then plan will be re-scanned
1470  * by first ExecProcNode.
1471  */
1472  if (innerPlan->chgParam == NULL)
1474  }
1475  }
1476 
1477  /* Always reset intra-tuple state */
1478  node->hj_CurHashValue = 0;
1479  node->hj_CurBucketNo = 0;
1481  node->hj_CurTuple = NULL;
1482 
1483  node->hj_MatchedOuter = false;
1484  node->hj_FirstOuterTupleSlot = NULL;
1485 
1486  /*
1487  * if chgParam of subnode is not null then plan will be re-scanned by
1488  * first ExecProcNode.
1489  */
1490  if (outerPlan->chgParam == NULL)
1492 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:78
void * palloc0(Size size)
Definition: mcxt.c:1257
void ExecHashAccumInstrumentation(HashInstrumentation *instrument, HashJoinTable hashtable)
Definition: nodeHash.c:2847
void ExecHashTableResetMatchFlags(HashJoinTable hashtable)
Definition: nodeHash.c:2324
#define HJ_FILL_INNER(hjstate)
Definition: nodeHashjoin.c:190
#define HJ_NEED_NEW_OUTER
Definition: nodeHashjoin.c:181
#define castNode(_type_, nodeptr)
Definition: nodes.h:197
HashJoinTable hashtable
Definition: execnodes.h:2662
HashInstrumentation * hinstrument
Definition: execnodes.h:2678
Instrumentation * instrument
Definition: execnodes.h:1047

References Assert(), castNode, 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, innerPlan, innerPlanState, PlanState::instrument, INVALID_SKEW_BUCKET_NO, HashJoinTableData::nbatch, outerPlan, outerPlanState, palloc0(), and HashState::ps.

Referenced by ExecReScan().

◆ ExecShutdownHashJoin()

void ExecShutdownHashJoin ( HashJoinState node)

Definition at line 1495 of file nodeHashjoin.c.

1496 {
1497  if (node->hj_HashTable)
1498  {
1499  /*
1500  * Detach from shared state before DSM memory goes away. This makes
1501  * sure that we don't have any pointers into DSM memory by the time
1502  * ExecEndHashJoin runs.
1503  */
1506  }
1507 }

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

Referenced by ExecShutdownNode_walker().