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

Function gather_merge_setup

src/backend/executor/nodeGatherMerge.c:395–434  ·  view source on GitHub ↗

* Set up the data structures that we'll need for Gather Merge. * * We allocate these once on the basis of gm->num_workers, which is an * upper bound for the number of workers we'll actually have. During * a rescan, we reset the structures to empty. This approach simplifies * not leaking memory across rescans. * * In the gm_slots[] array, index 0 is for the leader, and indexes 1 to n * ar

Source from the content-addressed store, hash-verified

393 * 0 to n-1; it has no entry for the leader.
394 */
395static void
396gather_merge_setup(GatherMergeState *gm_state)
397{
398 GatherMerge *gm = castNode(GatherMerge, gm_state->ps.plan);
399 int nreaders = gm->num_workers;
400 int i;
401
402 /*
403 * Allocate gm_slots for the number of workers + one more slot for leader.
404 * Slot 0 is always for the leader. Leader always calls ExecProcNode() to
405 * read the tuple, and then stores it directly into its gm_slots entry.
406 * For other slots, code below will call ExecInitExtraTupleSlot() to
407 * create a slot for the worker's results. Note that during any single
408 * scan, we might have fewer than num_workers available workers, in which
409 * case the extra array entries go unused.
410 */
411 gm_state->gm_slots = (TupleTableSlot **)
412 palloc0((nreaders + 1) * sizeof(TupleTableSlot *));
413
414 /* Allocate the tuple slot and tuple array for each worker */
415 gm_state->gm_tuple_buffers = (GMReaderTupleBuffer *)
416 palloc0(nreaders * sizeof(GMReaderTupleBuffer));
417
418 for (i = 0; i < nreaders; i++)
419 {
420 /* Allocate the tuple array with length MAX_TUPLE_STORE */
421 gm_state->gm_tuple_buffers[i].tuple =
422 (MinimalTuple *) palloc0(sizeof(MinimalTuple) * MAX_TUPLE_STORE);
423
424 /* Initialize tuple slot for worker */
425 gm_state->gm_slots[i + 1] =
426 ExecInitExtraTupleSlot(gm_state->ps.state, gm_state->tupDesc,
427 &TTSOpsMinimalTuple);
428 }
429
430 /* Allocate the resources for the merge */
431 gm_state->gm_heap = binaryheap_allocate(nreaders + 1,
432 heap_compare_slots,
433 gm_state);
434}
435
436/*
437 * Initialize the Gather Merge.

Callers 1

ExecInitGatherMergeFunction · 0.85

Calls 3

ExecInitExtraTupleSlotFunction · 0.85
binaryheap_allocateFunction · 0.85
palloc0Function · 0.50

Tested by

no test coverage detected