PostgreSQL Source Code git master
Loading...
Searching...
No Matches
nodeGatherMerge.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * nodeGatherMerge.c
4 * Scan a plan in multiple workers, and do order-preserving merge.
5 *
6 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * IDENTIFICATION
10 * src/backend/executor/nodeGatherMerge.c
11 *
12 *-------------------------------------------------------------------------
13 */
14
15#include "postgres.h"
16
17#include "access/htup_details.h"
18#include "executor/executor.h"
21#include "executor/tqueue.h"
22#include "lib/binaryheap.h"
23#include "miscadmin.h"
24#include "optimizer/optimizer.h"
25#include "utils/sortsupport.h"
26
27/*
28 * When we read tuples from workers, it's a good idea to read several at once
29 * for efficiency when possible: this minimizes context-switching overhead.
30 * But reading too many at a time wastes memory without improving performance.
31 * We'll read up to MAX_TUPLE_STORE tuples (in addition to the first one).
32 */
33#define MAX_TUPLE_STORE 10
34
35/*
36 * Pending-tuple array for each worker. This holds additional tuples that
37 * we were able to fetch from the worker, but can't process yet. In addition,
38 * this struct holds the "done" flag indicating the worker is known to have
39 * no more tuples. (We do not use this struct for the leader; we don't keep
40 * any pending tuples for the leader, and the need_to_scan_locally flag serves
41 * as its "done" indicator.)
42 */
43typedef struct GMReaderTupleBuffer
44{
45 MinimalTuple *tuple; /* array of length MAX_TUPLE_STORE */
46 int nTuples; /* number of tuples currently stored */
47 int readCounter; /* index of next tuple to extract */
48 bool done; /* true if reader is known exhausted */
50
52static int32 heap_compare_slots(Datum a, Datum b, void *arg);
55 bool nowait, bool *done);
60static bool gather_merge_readnext(GatherMergeState *gm_state, int reader,
61 bool nowait);
62static void load_tuple_array(GatherMergeState *gm_state, int reader);
63
64/* ----------------------------------------------------------------
65 * ExecInitGather
66 * ----------------------------------------------------------------
67 */
69ExecInitGatherMerge(GatherMerge *node, EState *estate, int eflags)
70{
73 TupleDesc tupDesc;
74
75 /* Gather merge node doesn't have innerPlan node. */
76 Assert(innerPlan(node) == NULL);
77
78 /*
79 * create state structure
80 */
82 gm_state->ps.plan = (Plan *) node;
83 gm_state->ps.state = estate;
84 gm_state->ps.ExecProcNode = ExecGatherMerge;
85
86 gm_state->initialized = false;
87 gm_state->gm_initialized = false;
88 gm_state->tuples_needed = -1;
89
90 /*
91 * Miscellaneous initialization
92 *
93 * create expression context for node
94 */
95 ExecAssignExprContext(estate, &gm_state->ps);
96
97 /*
98 * GatherMerge doesn't support checking a qual (it's always more efficient
99 * to do it in the child node).
100 */
101 Assert(!node->plan.qual);
102
103 /*
104 * now initialize outer plan
105 */
106 outerNode = outerPlan(node);
107 outerPlanState(gm_state) = ExecInitNode(outerNode, estate, eflags);
108
109 /*
110 * Leader may access ExecProcNode result directly (if
111 * need_to_scan_locally), or from workers via tuple queue. So we can't
112 * trivially rely on the slot type being fixed for expressions evaluated
113 * within this node.
114 */
115 gm_state->ps.outeropsset = true;
116 gm_state->ps.outeropsfixed = false;
117
118 /*
119 * Store the tuple descriptor into gather merge state, so we can use it
120 * while initializing the gather merge slots.
121 */
123 gm_state->tupDesc = tupDesc;
124
125 /*
126 * Initialize result type and projection.
127 */
130
131 /*
132 * Without projections result slot type is not trivially known, see
133 * comment above.
134 */
135 if (gm_state->ps.ps_ProjInfo == NULL)
136 {
137 gm_state->ps.resultopsset = true;
138 gm_state->ps.resultopsfixed = false;
139 }
140
141 /*
142 * initialize sort-key information
143 */
144 if (node->numCols)
145 {
146 int i;
147
148 gm_state->gm_nkeys = node->numCols;
149 gm_state->gm_sortkeys = palloc0_array(SortSupportData, node->numCols);
150
151 for (i = 0; i < node->numCols; i++)
152 {
153 SortSupport sortKey = gm_state->gm_sortkeys + i;
154
156 sortKey->ssup_collation = node->collations[i];
157 sortKey->ssup_nulls_first = node->nullsFirst[i];
158 sortKey->ssup_attno = node->sortColIdx[i];
159
160 /*
161 * We don't perform abbreviated key conversion here, for the same
162 * reasons that it isn't used in MergeAppend
163 */
164 sortKey->abbreviate = false;
165
166 PrepareSortSupportFromOrderingOp(node->sortOperators[i], sortKey);
167 }
168 }
169
170 /* Now allocate the workspace for gather merge */
172
173 return gm_state;
174}
175
176/* ----------------------------------------------------------------
177 * ExecGatherMerge(node)
178 *
179 * Scans the relation via multiple workers and returns
180 * the next qualifying tuple.
181 * ----------------------------------------------------------------
182 */
183static TupleTableSlot *
185{
187 TupleTableSlot *slot;
188 ExprContext *econtext;
189
191
192 /*
193 * As with Gather, we don't launch workers until this node is actually
194 * executed.
195 */
196 if (!node->initialized)
197 {
198 EState *estate = node->ps.state;
200
201 /*
202 * Sometimes we might have to run without parallelism; but if parallel
203 * mode is active then we can try to fire up some workers.
204 */
205 if (gm->num_workers > 0 && estate->es_use_parallel_mode)
206 {
207 ParallelContext *pcxt;
208
209 /* Initialize, or re-initialize, shared state needed by workers. */
210 if (!node->pei)
212 estate,
213 gm->initParam,
214 gm->num_workers,
215 node->tuples_needed);
216 else
218 node->pei,
219 gm->initParam);
220
221 /* Try to launch workers. */
222 pcxt = node->pei->pcxt;
224 /* We save # workers launched for the benefit of EXPLAIN */
226
227 /*
228 * Count number of workers originally wanted and actually
229 * launched.
230 */
233
234 /* Set up tuple queue readers to read the results. */
235 if (pcxt->nworkers_launched > 0)
236 {
238 /* Make a working array showing the active readers */
239 node->nreaders = pcxt->nworkers_launched;
240 node->reader = (TupleQueueReader **)
241 palloc(node->nreaders * sizeof(TupleQueueReader *));
242 memcpy(node->reader, node->pei->reader,
243 node->nreaders * sizeof(TupleQueueReader *));
244 }
245 else
246 {
247 /* No workers? Then never mind. */
248 node->nreaders = 0;
249 node->reader = NULL;
250 }
251 }
252
253 /* allow leader to participate if enabled or no choice */
254 if (parallel_leader_participation || node->nreaders == 0)
255 node->need_to_scan_locally = true;
256 node->initialized = true;
257 }
258
259 /*
260 * Reset per-tuple memory context to free any expression evaluation
261 * storage allocated in the previous tuple cycle.
262 */
263 econtext = node->ps.ps_ExprContext;
264 ResetExprContext(econtext);
265
266 /*
267 * Get next tuple, either from one of our workers, or by running the plan
268 * ourselves.
269 */
270 slot = gather_merge_getnext(node);
271 if (TupIsNull(slot))
272 return NULL;
273
274 /* If no projection is required, we're done. */
275 if (node->ps.ps_ProjInfo == NULL)
276 return slot;
277
278 /*
279 * Form the result tuple using ExecProject(), and return it.
280 */
281 econtext->ecxt_outertuple = slot;
282 return ExecProject(node->ps.ps_ProjInfo);
283}
284
285/* ----------------------------------------------------------------
286 * ExecEndGatherMerge
287 *
288 * frees any storage allocated through C routines.
289 * ----------------------------------------------------------------
290 */
291void
293{
294 ExecEndNode(outerPlanState(node)); /* let children clean up first */
296}
297
298/* ----------------------------------------------------------------
299 * ExecShutdownGatherMerge
300 *
301 * Destroy the setup for parallel workers including parallel context.
302 * ----------------------------------------------------------------
303 */
304void
306{
308
309 /* Now destroy the parallel context. */
310 if (node->pei != NULL)
311 {
313 node->pei = NULL;
314 }
315}
316
317/* ----------------------------------------------------------------
318 * ExecShutdownGatherMergeWorkers
319 *
320 * Stop all the parallel workers.
321 * ----------------------------------------------------------------
322 */
323static void
325{
326 if (node->pei != NULL)
327 ExecParallelFinish(node->pei);
328
329 /* Flush local copy of reader array */
330 if (node->reader)
331 pfree(node->reader);
332 node->reader = NULL;
333}
334
335/* ----------------------------------------------------------------
336 * ExecReScanGatherMerge
337 *
338 * Prepare to re-scan the result of a GatherMerge.
339 * ----------------------------------------------------------------
340 */
341void
343{
344 GatherMerge *gm = (GatherMerge *) node->ps.plan;
346
347 /* Make sure any existing workers are gracefully shut down */
349
350 /* Free any unused tuples, so we don't leak memory across rescans */
352
353 /* Mark node so that shared state will be rebuilt at next call */
354 node->initialized = false;
355 node->gm_initialized = false;
356
357 /*
358 * Set child node's chgParam to tell it that the next scan might deliver a
359 * different set of rows within the leader process. (The overall rowset
360 * shouldn't change, but the leader process's subset might; hence nodes
361 * between here and the parallel table scan node mustn't optimize on the
362 * assumption of an unchanging rowset.)
363 */
364 if (gm->rescan_param >= 0)
365 outerPlan->chgParam = bms_add_member(outerPlan->chgParam,
366 gm->rescan_param);
367
368 /*
369 * If chgParam of subnode is not null then plan will be re-scanned by
370 * first ExecProcNode. Note: because this does nothing if we have a
371 * rescan_param, it's currently guaranteed that parallel-aware child nodes
372 * will not see a ReScan call until after they get a ReInitializeDSM call.
373 * That ordering might not be something to rely on, though. A good rule
374 * of thumb is that ReInitializeDSM should reset only shared state, ReScan
375 * should reset only local state, and anything that depends on both of
376 * those steps being finished must wait until the first ExecProcNode call.
377 */
378 if (outerPlan->chgParam == NULL)
380}
381
382/*
383 * Set up the data structures that we'll need for Gather Merge.
384 *
385 * We allocate these once on the basis of gm->num_workers, which is an
386 * upper bound for the number of workers we'll actually have. During
387 * a rescan, we reset the structures to empty. This approach simplifies
388 * not leaking memory across rescans.
389 *
390 * In the gm_slots[] array, index 0 is for the leader, and indexes 1 to n
391 * are for workers. The values placed into gm_heap correspond to indexes
392 * in gm_slots[]. The gm_tuple_buffers[] array, however, is indexed from
393 * 0 to n-1; it has no entry for the leader.
394 */
395static void
397{
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 = palloc0_array(MinimalTuple, MAX_TUPLE_STORE);
422
423 /* Initialize tuple slot for worker */
424 gm_state->gm_slots[i + 1] =
425 ExecInitExtraTupleSlot(gm_state->ps.state, gm_state->tupDesc,
427 }
428
429 /* Allocate the resources for the merge */
430 gm_state->gm_heap = binaryheap_allocate(nreaders + 1,
432 gm_state);
433}
434
435/*
436 * Initialize the Gather Merge.
437 *
438 * Reset data structures to ensure they're empty. Then pull at least one
439 * tuple from leader + each worker (or set its "done" indicator), and set up
440 * the heap.
441 */
442static void
444{
445 int nreaders = gm_state->nreaders;
446 bool nowait = true;
447 int i;
448
449 /* Assert that gather_merge_setup made enough space */
450 Assert(nreaders <= castNode(GatherMerge, gm_state->ps.plan)->num_workers);
451
452 /* Reset leader's tuple slot to empty */
453 gm_state->gm_slots[0] = NULL;
454
455 /* Reset the tuple slot and tuple array for each worker */
456 for (i = 0; i < nreaders; i++)
457 {
458 /* Reset tuple array to empty */
459 gm_state->gm_tuple_buffers[i].nTuples = 0;
460 gm_state->gm_tuple_buffers[i].readCounter = 0;
461 /* Reset done flag to not-done */
462 gm_state->gm_tuple_buffers[i].done = false;
463 /* Ensure output slot is empty */
464 ExecClearTuple(gm_state->gm_slots[i + 1]);
465 }
466
467 /* Reset binary heap to empty */
468 binaryheap_reset(gm_state->gm_heap);
469
470 /*
471 * First, try to read a tuple from each worker (including leader) in
472 * nowait mode. After this, if not all workers were able to produce a
473 * tuple (or a "done" indication), then re-read from remaining workers,
474 * this time using wait mode. Add all live readers (those producing at
475 * least one tuple) to the heap.
476 */
477reread:
478 for (i = 0; i <= nreaders; i++)
479 {
481
482 /* skip this source if already known done */
483 if ((i == 0) ? gm_state->need_to_scan_locally :
484 !gm_state->gm_tuple_buffers[i - 1].done)
485 {
486 if (TupIsNull(gm_state->gm_slots[i]))
487 {
488 /* Don't have a tuple yet, try to get one */
489 if (gather_merge_readnext(gm_state, i, nowait))
492 }
493 else
494 {
495 /*
496 * We already got at least one tuple from this worker, but
497 * might as well see if it has any more ready by now.
498 */
500 }
501 }
502 }
503
504 /* need not recheck leader, since nowait doesn't matter for it */
505 for (i = 1; i <= nreaders; i++)
506 {
507 if (!gm_state->gm_tuple_buffers[i - 1].done &&
508 TupIsNull(gm_state->gm_slots[i]))
509 {
510 nowait = false;
511 goto reread;
512 }
513 }
514
515 /* Now heapify the heap. */
516 binaryheap_build(gm_state->gm_heap);
517
518 gm_state->gm_initialized = true;
519}
520
521/*
522 * Clear out the tuple table slot, and any unused pending tuples,
523 * for each gather merge input.
524 */
525static void
527{
528 int i;
529
530 for (i = 0; i < gm_state->nreaders; i++)
531 {
532 GMReaderTupleBuffer *tuple_buffer = &gm_state->gm_tuple_buffers[i];
533
534 while (tuple_buffer->readCounter < tuple_buffer->nTuples)
535 pfree(tuple_buffer->tuple[tuple_buffer->readCounter++]);
536
537 ExecClearTuple(gm_state->gm_slots[i + 1]);
538 }
539}
540
541/*
542 * Read the next tuple for gather merge.
543 *
544 * Fetch the sorted tuple out of the heap.
545 */
546static TupleTableSlot *
548{
549 int i;
550
551 if (!gm_state->gm_initialized)
552 {
553 /*
554 * First time through: pull the first tuple from each participant, and
555 * set up the heap.
556 */
558 }
559 else
560 {
561 /*
562 * Otherwise, pull the next tuple from whichever participant we
563 * returned from last time, and reinsert that participant's index into
564 * the heap, because it might now compare differently against the
565 * other elements of the heap.
566 */
568
569 if (gather_merge_readnext(gm_state, i, false))
571 else
572 {
573 /* reader exhausted, remove it from heap */
575 }
576 }
577
578 if (binaryheap_empty(gm_state->gm_heap))
579 {
580 /* All the queues are exhausted, and so is the heap */
582 return NULL;
583 }
584 else
585 {
586 /* Return next tuple from whichever participant has the leading one */
588 return gm_state->gm_slots[i];
589 }
590}
591
592/*
593 * Read tuple(s) for given reader in nowait mode, and load into its tuple
594 * array, until we have MAX_TUPLE_STORE of them or would have to block.
595 */
596static void
598{
600 int i;
601
602 /* Don't do anything if this is the leader. */
603 if (reader == 0)
604 return;
605
606 tuple_buffer = &gm_state->gm_tuple_buffers[reader - 1];
607
608 /* If there's nothing in the array, reset the counters to zero. */
609 if (tuple_buffer->nTuples == tuple_buffer->readCounter)
610 tuple_buffer->nTuples = tuple_buffer->readCounter = 0;
611
612 /* Try to fill additional slots in the array. */
613 for (i = tuple_buffer->nTuples; i < MAX_TUPLE_STORE; i++)
614 {
615 MinimalTuple tuple;
616
618 reader,
619 true,
620 &tuple_buffer->done);
621 if (!tuple)
622 break;
623 tuple_buffer->tuple[i] = tuple;
624 tuple_buffer->nTuples++;
625 }
626}
627
628/*
629 * Store the next tuple for a given reader into the appropriate slot.
630 *
631 * Returns true if successful, false if not (either reader is exhausted,
632 * or we didn't want to wait for a tuple). Sets done flag if reader
633 * is found to be exhausted.
634 */
635static bool
637{
640
641 /*
642 * If we're being asked to generate a tuple from the leader, then we just
643 * call ExecProcNode as normal to produce one.
644 */
645 if (reader == 0)
646 {
647 if (gm_state->need_to_scan_locally)
648 {
651 EState *estate = gm_state->ps.state;
652
653 /* Install our DSA area while executing the plan. */
654 estate->es_query_dsa = gm_state->pei ? gm_state->pei->area : NULL;
656 estate->es_query_dsa = NULL;
657
659 {
660 gm_state->gm_slots[0] = outerTupleSlot;
661 return true;
662 }
663 /* need_to_scan_locally serves as "done" flag for leader */
664 gm_state->need_to_scan_locally = false;
665 }
666 return false;
667 }
668
669 /* Otherwise, check the state of the relevant tuple buffer. */
670 tuple_buffer = &gm_state->gm_tuple_buffers[reader - 1];
671
672 if (tuple_buffer->nTuples > tuple_buffer->readCounter)
673 {
674 /* Return any tuple previously read that is still buffered. */
675 tup = tuple_buffer->tuple[tuple_buffer->readCounter++];
676 }
677 else if (tuple_buffer->done)
678 {
679 /* Reader is known to be exhausted. */
680 return false;
681 }
682 else
683 {
684 /* Read and buffer next tuple. */
686 reader,
687 nowait,
688 &tuple_buffer->done);
689 if (!tup)
690 return false;
691
692 /*
693 * Attempt to read more tuples in nowait mode and store them in the
694 * pending-tuple array for the reader.
695 */
696 load_tuple_array(gm_state, reader);
697 }
698
699 Assert(tup);
700
701 /* Build the TupleTableSlot for the given tuple */
702 ExecStoreMinimalTuple(tup, /* tuple to store */
703 gm_state->gm_slots[reader], /* slot in which to
704 * store the tuple */
705 true); /* pfree tuple when done with it */
706
707 return true;
708}
709
710/*
711 * Attempt to read a tuple from given worker.
712 */
713static MinimalTuple
715 bool *done)
716{
717 TupleQueueReader *reader;
719
720 /* Check for async events, particularly messages from workers. */
722
723 /*
724 * Attempt to read a tuple.
725 *
726 * Note that TupleQueueReaderNext will just return NULL for a worker which
727 * fails to initialize. We'll treat that worker as having produced no
728 * tuples; WaitForParallelWorkersToFinish will error out when we get
729 * there.
730 */
731 reader = gm_state->reader[nreader - 1];
732 tup = TupleQueueReaderNext(reader, nowait, done);
733
734 /*
735 * Since we'll be buffering these across multiple calls, we need to make a
736 * copy.
737 */
738 return tup ? heap_copy_minimal_tuple(tup, 0) : NULL;
739}
740
741/*
742 * We have one slot for each item in the heap array. We use SlotNumber
743 * to store slot indexes. This doesn't actually provide any formal
744 * type-safety, but it makes the code more self-documenting.
745 */
747
748/*
749 * Compare the tuples in the two given slots.
750 */
751static int32
753{
757
760 int nkey;
761
764
765 for (nkey = 0; nkey < node->gm_nkeys; nkey++)
766 {
769 Datum datum1,
770 datum2;
771 bool isNull1,
772 isNull2;
773 int compare;
774
775 datum1 = slot_getattr(s1, attno, &isNull1);
776 datum2 = slot_getattr(s2, attno, &isNull2);
777
780 sortKey);
781 if (compare != 0)
782 {
784 return compare;
785 }
786 }
787 return 0;
788}
int16 AttrNumber
Definition attnum.h:21
void LaunchParallelWorkers(ParallelContext *pcxt)
Definition parallel.c:583
void binaryheap_build(binaryheap *heap)
Definition binaryheap.c:136
void binaryheap_replace_first(binaryheap *heap, bh_node_type d)
Definition binaryheap.c:253
void binaryheap_reset(binaryheap *heap)
Definition binaryheap.c:61
bh_node_type binaryheap_first(binaryheap *heap)
Definition binaryheap.c:175
bh_node_type binaryheap_remove_first(binaryheap *heap)
Definition binaryheap.c:190
void binaryheap_add_unordered(binaryheap *heap, bh_node_type d)
Definition binaryheap.c:114
binaryheap * binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)
Definition binaryheap.c:37
#define binaryheap_empty(h)
Definition binaryheap.h:65
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition bitmapset.c:799
#define INVERT_COMPARE_RESULT(var)
Definition c.h:1195
#define Assert(condition)
Definition c.h:945
int32_t int32
Definition c.h:614
Datum arg
Definition elog.c:1322
void ExecReScan(PlanState *node)
Definition execAmi.c:78
void ExecParallelCleanup(ParallelExecutorInfo *pei)
void ExecParallelReinitialize(PlanState *planstate, ParallelExecutorInfo *pei, Bitmapset *sendParams)
void ExecParallelCreateReaders(ParallelExecutorInfo *pei)
ParallelExecutorInfo * ExecInitParallelPlan(PlanState *planstate, EState *estate, Bitmapset *sendParams, int nworkers, int64 tuples_needed)
void ExecParallelFinish(ParallelExecutorInfo *pei)
void ExecEndNode(PlanState *node)
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
void ExecInitResultTypeTL(PlanState *planstate)
TupleTableSlot * ExecStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
const TupleTableSlotOps TTSOpsMinimalTuple
Definition execTuples.c:86
TupleDesc ExecGetResultType(PlanState *planstate)
Definition execUtils.c:500
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition execUtils.c:490
void ExecConditionalAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc, int varno)
Definition execUtils.c:608
#define outerPlanState(node)
Definition execnodes.h:1273
static TupleTableSlot * ExecProject(ProjectionInfo *projInfo)
Definition executor.h:486
#define ResetExprContext(econtext)
Definition executor.h:654
static TupleTableSlot * ExecProcNode(PlanState *node)
Definition executor.h:315
#define palloc0_array(type, count)
Definition fe_memutils.h:77
static int compare(const void *arg1, const void *arg2)
Definition geqo_pool.c:144
MinimalTuple heap_copy_minimal_tuple(MinimalTuple mtup, Size extra)
Definition heaptuple.c:1490
int b
Definition isn.c:74
int a
Definition isn.c:73
int i
Definition isn.c:77
void pfree(void *pointer)
Definition mcxt.c:1616
void * palloc0(Size size)
Definition mcxt.c:1417
void * palloc(Size size)
Definition mcxt.c:1387
MemoryContext CurrentMemoryContext
Definition mcxt.c:160
#define CHECK_FOR_INTERRUPTS()
Definition miscadmin.h:123
static void gather_merge_init(GatherMergeState *gm_state)
static void gather_merge_setup(GatherMergeState *gm_state)
static int32 heap_compare_slots(Datum a, Datum b, void *arg)
void ExecReScanGatherMerge(GatherMergeState *node)
static void gather_merge_clear_tuples(GatherMergeState *gm_state)
void ExecShutdownGatherMerge(GatherMergeState *node)
static void load_tuple_array(GatherMergeState *gm_state, int reader)
int32 SlotNumber
GatherMergeState * ExecInitGatherMerge(GatherMerge *node, EState *estate, int eflags)
static bool gather_merge_readnext(GatherMergeState *gm_state, int reader, bool nowait)
static void ExecShutdownGatherMergeWorkers(GatherMergeState *node)
static MinimalTuple gm_readnext_tuple(GatherMergeState *gm_state, int nreader, bool nowait, bool *done)
void ExecEndGatherMerge(GatherMergeState *node)
static TupleTableSlot * gather_merge_getnext(GatherMergeState *gm_state)
#define MAX_TUPLE_STORE
static TupleTableSlot * ExecGatherMerge(PlanState *pstate)
#define makeNode(_type_)
Definition nodes.h:161
#define castNode(_type_, nodeptr)
Definition nodes.h:182
bool parallel_leader_participation
Definition planner.c:70
#define innerPlan(node)
Definition plannodes.h:264
#define outerPlan(node)
Definition plannodes.h:265
uint64_t Datum
Definition postgres.h:70
static Datum Int32GetDatum(int32 X)
Definition postgres.h:212
static int32 DatumGetInt32(Datum X)
Definition postgres.h:202
static int fb(int x)
char * s1
char * s2
#define OUTER_VAR
Definition primnodes.h:244
void PrepareSortSupportFromOrderingOp(Oid orderingOp, SortSupport ssup)
static int ApplySortComparator(Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup)
struct dsa_area * es_query_dsa
Definition execnodes.h:764
int es_parallel_workers_to_launch
Definition execnodes.h:758
bool es_use_parallel_mode
Definition execnodes.h:756
int es_parallel_workers_launched
Definition execnodes.h:760
TupleTableSlot * ecxt_outertuple
Definition execnodes.h:288
MinimalTuple * tuple
struct ParallelExecutorInfo * pei
Definition execnodes.h:2648
struct TupleQueueReader ** reader
Definition execnodes.h:2654
SortSupport gm_sortkeys
Definition execnodes.h:2647
TupleTableSlot ** gm_slots
Definition execnodes.h:2653
bool need_to_scan_locally
Definition execnodes.h:2642
int nworkers_launched
Definition parallel.h:39
int nworkers_to_launch
Definition parallel.h:38
ParallelContext * pcxt
struct TupleQueueReader ** reader
Plan * plan
Definition execnodes.h:1177
EState * state
Definition execnodes.h:1179
ExprContext * ps_ExprContext
Definition execnodes.h:1216
ProjectionInfo * ps_ProjInfo
Definition execnodes.h:1217
List * qual
Definition plannodes.h:235
AttrNumber ssup_attno
Definition sortsupport.h:81
MemoryContext ssup_cxt
Definition sortsupport.h:66
MinimalTuple TupleQueueReaderNext(TupleQueueReader *reader, bool nowait, bool *done)
Definition tqueue.c:176
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
Definition tuptable.h:417
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition tuptable.h:476
#define TupIsNull(slot)
Definition tuptable.h:325