MCPcopy Create free account
hub / github.com/apache/cloudberry / ExecHashTableCreate

Function ExecHashTableCreate

src/backend/executor/nodeHash.c:538–782  ·  view source on GitHub ↗

---------------------------------------------------------------- * ExecHashTableCreate * * create an empty hashtable data structure for hashjoin. * ---------------------------------------------------------------- */

Source from the content-addressed store, hash-verified

536 * ----------------------------------------------------------------
537 */
538HashJoinTable
539ExecHashTableCreate(HashState *state, HashJoinState *hjstate,
540 List *hashOperators, List *hashCollations,
541 bool keepNulls, uint64 operatorMemKB)
542{
543 Hash *node;
544 HashJoinTable hashtable;
545 Plan *outerNode;
546 size_t space_allowed;
547 int nbuckets;
548 int nbatch;
549 double rows;
550 int num_skew_mcvs;
551 int log2_nbuckets;
552 int nkeys;
553 int i;
554 ListCell *ho;
555 ListCell *hc;
556 MemoryContext oldcxt;
557
558 /*
559 * Get information about the size of the relation to be hashed (it's the
560 * "outer" subtree of this node, but the inner relation of the hashjoin).
561 * Compute the appropriate size of the hash table.
562 */
563 node = (Hash *) state->ps.plan;
564 outerNode = outerPlan(node);
565
566 /*
567 * If this is shared hash table with a partial plan, then we can't use
568 * outerNode->plan_rows to estimate its size. We need an estimate of the
569 * total number of rows across all copies of the partial plan.
570 */
571 rows = node->plan.parallel_aware ? node->rows_total : outerNode->plan_rows;
572
573 ExecChooseHashTableSize(rows, outerNode->plan_width,
574 OidIsValid(node->skewTable),
575 operatorMemKB,
576 state->parallel_state != NULL,
577 state->parallel_state != NULL ?
578 state->parallel_state->nparticipants - 1 : 0,
579 &space_allowed,
580 &nbuckets, &nbatch, &num_skew_mcvs);
581
582 /* nbuckets must be a power of 2 */
583 log2_nbuckets = my_log2(nbuckets);
584 Assert(nbuckets == (1 << log2_nbuckets));
585
586 /*
587 * Initialize the hash table control block.
588 *
589 * The hashtable control block is just palloc'd from the executor's
590 * per-query memory context. Everything else should be kept inside the
591 * subsidiary hashCxt or batchCxt.
592 */
593 hashtable = (HashJoinTable) palloc0(sizeof(HashJoinTableData));
594 hashtable->nbuckets = nbuckets;
595 hashtable->nbuckets_original = nbuckets;

Callers 1

ExecHashJoinImplFunction · 0.85

Calls 15

ExecChooseHashTableSizeFunction · 0.85
my_log2Function · 0.85
MemoryContextSwitchToFunction · 0.85
list_lengthFunction · 0.85
forbothFunction · 0.85
get_op_hash_functionsFunction · 0.85
fmgr_infoFunction · 0.85
op_strictFunction · 0.85
PrepareTempTablespacesFunction · 0.85
BarrierAttachFunction · 0.85
BarrierArriveAndWaitFunction · 0.85
BarrierPhaseFunction · 0.85

Tested by

no test coverage detected