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

Function buildSubPlanHash

src/backend/executor/nodeSubplan.c:488–643  ·  view source on GitHub ↗

* buildSubPlanHash: load hash table by scanning subplan output. */

Source from the content-addressed store, hash-verified

486 * buildSubPlanHash: load hash table by scanning subplan output.
487 */
488static void
489buildSubPlanHash(SubPlanState *node, ExprContext *econtext)
490{
491 SubPlan *subplan = node->subplan;
492 PlanState *planstate = node->planstate;
493 int ncols = node->numCols;
494 ExprContext *innerecontext = node->innerecontext;
495 MemoryContext oldcontext;
496 long nbuckets;
497 TupleTableSlot *slot;
498
499 Assert(subplan->subLinkType == ANY_SUBLINK);
500
501 /*
502 * If we already had any hash tables, reset 'em; otherwise create empty
503 * hash table(s).
504 *
505 * If we need to distinguish accurately between FALSE and UNKNOWN (i.e.,
506 * NULL) results of the IN operation, then we have to store subplan output
507 * rows that are partly or wholly NULL. We store such rows in a separate
508 * hash table that we expect will be much smaller than the main table. (We
509 * can use hashing to eliminate partly-null rows that are not distinct. We
510 * keep them separate to minimize the cost of the inevitable full-table
511 * searches; see findPartialMatch.)
512 *
513 * If it's not necessary to distinguish FALSE and UNKNOWN, then we don't
514 * need to store subplan output rows that contain NULL.
515 */
516 MemoryContextReset(node->hashtablecxt);
517 node->havehashrows = false;
518 node->havenullrows = false;
519
520 nbuckets = (long) Min(planstate->plan->plan_rows, (double) LONG_MAX);
521 if (nbuckets < 1)
522 nbuckets = 1;
523
524 if (node->hashtable)
525 ResetTupleHashTable(node->hashtable);
526 else
527 node->hashtable = BuildTupleHashTableExt(node->parent,
528 node->descRight,
529 ncols,
530 node->keyColIdx,
531 node->tab_eq_funcoids,
532 node->tab_hash_funcs,
533 node->tab_collations,
534 nbuckets,
535 0,
536 node->planstate->state->es_query_cxt,
537 node->hashtablecxt,
538 node->hashtempcxt,
539 false);
540
541 if (!subplan->unknownEqFalse)
542 {
543 if (ncols == 1)
544 nbuckets = 1; /* there can only be one entry */
545 else

Callers 1

ExecHashSubPlanFunction · 0.85

Calls 12

MemoryContextResetFunction · 0.85
ResetTupleHashTableFunction · 0.85
BuildTupleHashTableExtFunction · 0.85
MemoryContextSwitchToFunction · 0.85
ExecReScanFunction · 0.85
ExecProcNodeFunction · 0.85
slot_getattrFunction · 0.85
ExecProjectFunction · 0.85
slotNoNullsFunction · 0.85
LookupTupleHashEntryFunction · 0.85
ExecClearTupleFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected