99 #define INSTRUMENT_SORT_GROUP(node, groupName) \ 101 if ((node)->ss.ps.instrument != NULL) \ 103 if ((node)->shared_info && (node)->am_worker) \ 105 Assert(IsParallelWorker()); \ 106 Assert(ParallelWorkerNumber <= (node)->shared_info->num_workers); \ 107 instrumentSortedGroup(&(node)->shared_info->sinfo[ParallelWorkerNumber].groupName##GroupInfo, \ 108 (node)->groupName##_state); \ 112 instrumentSortedGroup(&(node)->incsort_info.groupName##GroupInfo, \ 113 (node)->groupName##_state); \ 186 elog(
ERROR,
"missing equality operator for ordering operator %u",
191 elog(
ERROR,
"missing function for operator %u", equalityOp);
225 for (
int i = nPresortedCols - 1;
i >= 0;
i--)
239 if (isnullA || isnullB)
241 if (isnullA == isnullB)
292 bool lastTuple =
false;
293 bool firstTuple =
true;
434 SO_printf(
"Setting execution_status to INCSORT_LOADPREFIXSORT (switchToPresortedPrefixMode)\n");
470 SO_printf(
"Setting execution_status to INCSORT_READPREFIXSORT (switchToPresortedPrefixMode)\n");
484 #define DEFAULT_MIN_GROUP_SIZE 32 496 #define DEFAULT_MAX_FULL_SORT_GROUP_SIZE (2 * DEFAULT_MIN_GROUP_SIZE) 577 SO1_printf(
"Re-calling switchToPresortedPrefixMode() because n_fullsort_remaining is > 0 (" INT64_FORMAT ")\n",
589 SO_printf(
"Setting execution_status to INCSORT_LOADFULLSORT (n_fullsort_remaining > 0)\n");
609 if (fullsort_state == NULL)
684 if (nTuples != minGroupSize)
715 SO_printf(
"Setting execution_status to INCSORT_READFULLSORT (final tuple)\n");
721 if (nTuples < minGroupSize)
737 if (nTuples == minGroupSize)
796 SO_printf(
"Setting execution_status to INCSORT_READFULLSORT (found end of group)\n");
851 nTuples,
Min(currentBound, nTuples));
852 nTuples =
Min(currentBound, nTuples);
855 SO1_printf(
"Setting n_fullsort_remaining to " INT64_FORMAT " and calling switchToPresortedPrefixMode()\n",
950 SO_printf(
"Setting execution_status to INCSORT_READPREFIXSORT (found end of group)\n");
995 SO_printf(
"ExecInitIncrementalSort: initializing sort node\n");
1011 incrsortstate->
bounded =
false;
1082 SO_printf(
"ExecInitIncrementalSort: sort node initialized\n");
1084 return incrsortstate;
1094 SO_printf(
"ExecEndIncrementalSort: shutting down sort node\n");
1123 SO_printf(
"ExecEndIncrementalSort: sort node shutdown\n");
bool tuplesort_used_bound(Tuplesortstate *state)
static TupleTableSlot * ExecCopySlot(TupleTableSlot *dstslot, TupleTableSlot *srcslot)
void tuplesort_performsort(Tuplesortstate *state)
ProjectionInfo * ps_ProjInfo
Instrumentation * instrument
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
#define ScanDirectionIsForward(direction)
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
#define castNode(_type_, nodeptr)
void ExecEndNode(PlanState *node)
void ExecEndIncrementalSort(IncrementalSortState *node)
shm_toc_estimator estimator
#define SizeForFunctionCallInfo(nargs)
Oid get_equality_op_for_ordering_op(Oid opno, bool *reverse)
void ExecReScan(PlanState *node)
IncrementalSortGroupInfo prefixsortGroupInfo
PresortedKeyData * presorted_keys
TupleTableSlot * ss_ScanTupleSlot
#define shm_toc_estimate_chunk(e, sz)
void tuplesort_get_stats(Tuplesortstate *state, TuplesortInstrumentation *stats)
#define OidIsValid(objectId)
static void preparePresortedCols(IncrementalSortState *node)
ScanDirection es_direction
IncrementalSortState * ExecInitIncrementalSort(IncrementalSort *node, EState *estate, int eflags)
int64 totalMemorySpaceUsed
Tuplesortstate * tuplesort_begin_heap(TupleDesc tupDesc, int nkeys, AttrNumber *attNums, Oid *sortOperators, Oid *sortCollations, bool *nullsFirstFlags, int workMem, SortCoordinate coordinate, bool randomAccess)
int64 n_fullsort_remaining
TupleTableSlot * ps_ResultTupleSlot
IncrementalSortInfo incsort_info
void tuplesort_reset(Tuplesortstate *state)
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
#define EXEC_FLAG_BACKWARD
#define outerPlanState(node)
bool tuplesort_gettupleslot(Tuplesortstate *state, bool forward, bool copy, TupleTableSlot *slot, Datum *abbrev)
void tuplesort_set_bound(Tuplesortstate *state, int64 bound)
#define FunctionCallInvoke(fcinfo)
TuplesortMethod sortMethod
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
static bool isCurrentGroup(IncrementalSortState *node, TupleTableSlot *pivot, TupleTableSlot *tuple)
IncrementalSortExecutionStatus execution_status
MemoryContext CurrentMemoryContext
static TupleTableSlot * ExecIncrementalSort(PlanState *pstate)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
void ExecIncrementalSortInitializeWorker(IncrementalSortState *node, ParallelWorkerContext *pwcxt)
void ExecIncrementalSortInitializeDSM(IncrementalSortState *node, ParallelContext *pcxt)
Size mul_size(Size s1, Size s2)
void * palloc0(Size size)
#define INSTRUMENT_SORT_GROUP(node, groupName)
ExecProcNodeMtd ExecProcNode
#define SO2_printf(s, p1, p2)
IncrementalSortGroupInfo fullsortGroupInfo
Size add_size(Size s1, Size s2)
static TupleTableSlot * ExecProcNode(PlanState *node)
void ExecReScanIncrementalSort(IncrementalSortState *node)
Tuplesortstate * fullsort_state
#define DEFAULT_MIN_GROUP_SIZE
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
RegProcedure get_opcode(Oid opno)
void ExecIncrementalSortRetrieveInstrumentation(IncrementalSortState *node)
#define Assert(condition)
struct IncrementalSortInfo IncrementalSortInfo
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
#define shm_toc_estimate_keys(e, cnt)
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
TupleDesc ExecGetResultType(PlanState *planstate)
static void switchToPresortedPrefixMode(PlanState *pstate)
Tuplesortstate * prefixsort_state
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
#define DEFAULT_MAX_FULL_SORT_GROUP_SIZE
void ExecIncrementalSortEstimate(IncrementalSortState *node, ParallelContext *pcxt)
TuplesortSpaceType spaceType
#define CHECK_FOR_INTERRUPTS()
TupleTableSlot * group_pivot
void ExecCreateScanSlotFromOuterPlan(EState *estate, ScanState *scanstate, const TupleTableSlotOps *tts_ops)
void tuplesort_end(Tuplesortstate *state)
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
SharedIncrementalSortInfo * shared_info
const TupleTableSlotOps TTSOpsMinimalTuple
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
TupleTableSlot * transfer_tuple
#define offsetof(type, field)
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
static void instrumentSortedGroup(IncrementalSortGroupInfo *groupInfo, Tuplesortstate *sortState)