84 #define NUM_TUPLESORTMETHODS 4
93 #define TUPLESORT_NONE 0
96 #define TUPLESORT_RANDOMACCESS (1 << 0)
99 #define TUPLESORT_ALLOWBOUNDED (1 << 1)
108 #define TupleSortUseBumpTupleCxt(opt) (((opt) & TUPLESORT_ALLOWBOUNDED) == 0)
255 #define PARALLEL_SORT(coordinate) (coordinate == NULL || \
256 (coordinate)->sharedsort == NULL ? 0 : \
257 (coordinate)->isWorker ? 1 : 2)
259 #define TuplesortstateGetPublic(state) ((TuplesortPublic *) state)
262 #define LogicalTapeReadExact(tape, ptr, len) \
264 if (LogicalTapeRead(tape, ptr, len) != (size_t) (len)) \
265 elog(ERROR, "unexpected end of data"); \
419 Oid *sortOperators,
Oid *sortCollations,
420 bool *nullsFirstFlags,
430 bool uniqueNullsNotDistinct,
447 Oid sortOperator,
Oid sortCollation,
static Datum values[MAXATTR]
static void freestate(struct nfa *nfa, struct state *s)
static pg_noinline void Size size
TuplesortMethod sortMethod
TuplesortSpaceType spaceType
MemoryContext maincontext
MemoryContext tuplecontext
MemoryContext sortcontext
SortTupleComparator comparetup
SortTupleComparator comparetup_tiebreak
IndexTuple tuplesort_getindextuple(Tuplesortstate *state, bool forward)
void tuplesort_rescan(Tuplesortstate *state)
void tuplesort_performsort(Tuplesortstate *state)
struct SortCoordinateData SortCoordinateData
int tuplesort_merge_order(int64 allowedMem)
void tuplesort_initialize_shared(Sharedsort *shared, int nWorkers, dsm_segment *seg)
Tuplesortstate * tuplesort_begin_common(int workMem, SortCoordinate coordinate, int sortopt)
HeapTuple tuplesort_getheaptuple(Tuplesortstate *state, bool forward)
void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)
Tuplesortstate * tuplesort_begin_index_hash(Relation heapRel, Relation indexRel, uint32 high_mask, uint32 low_mask, uint32 max_buckets, int workMem, SortCoordinate coordinate, int sortopt)
void tuplesort_reset(Tuplesortstate *state)
void tuplesort_putindextuplevalues(Tuplesortstate *state, Relation rel, ItemPointer self, const Datum *values, const bool *isnull)
bool tuplesort_skiptuples(Tuplesortstate *state, int64 ntuples, bool forward)
void tuplesort_puttupleslot(Tuplesortstate *state, TupleTableSlot *slot)
Tuplesortstate * tuplesort_begin_index_gist(Relation heapRel, Relation indexRel, int workMem, SortCoordinate coordinate, int sortopt)
bool tuplesort_used_bound(Tuplesortstate *state)
Tuplesortstate * tuplesort_begin_index_btree(Relation heapRel, Relation indexRel, bool enforceUnique, bool uniqueNullsNotDistinct, int workMem, SortCoordinate coordinate, int sortopt)
const char * tuplesort_space_type_name(TuplesortSpaceType t)
Tuplesortstate * tuplesort_begin_index_brin(int workMem, SortCoordinate coordinate, int sortopt)
Tuplesortstate * tuplesort_begin_datum(Oid datumType, Oid sortOperator, Oid sortCollation, bool nullsFirstFlag, int workMem, SortCoordinate coordinate, int sortopt)
Size tuplesort_estimate_shared(int nWorkers)
struct SortCoordinateData * SortCoordinate
void tuplesort_get_stats(Tuplesortstate *state, TuplesortInstrumentation *stats)
bool tuplesort_gettupleslot(Tuplesortstate *state, bool forward, bool copy, TupleTableSlot *slot, Datum *abbrev)
void tuplesort_end(Tuplesortstate *state)
void tuplesort_markpos(Tuplesortstate *state)
void tuplesort_puttuple_common(Tuplesortstate *state, SortTuple *tuple, bool useAbbrev, Size tuplen)
bool tuplesort_gettuple_common(Tuplesortstate *state, bool forward, SortTuple *stup)
Tuplesortstate * tuplesort_begin_cluster(TupleDesc tupDesc, Relation indexRel, int workMem, SortCoordinate coordinate, int sortopt)
void tuplesort_attach_shared(Sharedsort *shared, dsm_segment *seg)
void tuplesort_putbrintuple(Tuplesortstate *state, BrinTuple *tuple, Size size)
struct TuplesortInstrumentation TuplesortInstrumentation
void tuplesort_restorepos(Tuplesortstate *state)
int(* SortTupleComparator)(const SortTuple *a, const SortTuple *b, Tuplesortstate *state)
@ SORT_TYPE_EXTERNAL_SORT
@ SORT_TYPE_TOP_N_HEAPSORT
@ SORT_TYPE_STILL_IN_PROGRESS
@ SORT_TYPE_EXTERNAL_MERGE
void * tuplesort_readtup_alloc(Tuplesortstate *state, Size tuplen)
void tuplesort_putheaptuple(Tuplesortstate *state, HeapTuple tup)
bool tuplesort_getdatum(Tuplesortstate *state, bool forward, bool copy, Datum *val, bool *isNull, Datum *abbrev)
void tuplesort_set_bound(Tuplesortstate *state, int64 bound)
BrinTuple * tuplesort_getbrintuple(Tuplesortstate *state, Size *len, bool forward)
const char * tuplesort_method_name(TuplesortMethod m)
Tuplesortstate * tuplesort_begin_heap(TupleDesc tupDesc, int nkeys, AttrNumber *attNums, Oid *sortOperators, Oid *sortCollations, bool *nullsFirstFlags, int workMem, SortCoordinate coordinate, int sortopt)