PostgreSQL Source Code
git master
|
#include "access/itup.h"
#include "executor/tuptable.h"
#include "storage/dsm.h"
#include "utils/relcache.h"
Go to the source code of this file.
Data Structures | |
struct | SortCoordinateData |
struct | TuplesortInstrumentation |
Macros | |
#define | NUM_TUPLESORTMETHODS 4 |
#define | TUPLESORT_NONE 0 |
#define | TUPLESORT_RANDOMACCESS (1 << 0) |
#define | TUPLESORT_ALLOWBOUNDED (1 << 1) |
Typedefs | |
typedef struct Tuplesortstate | Tuplesortstate |
typedef struct Sharedsort | Sharedsort |
typedef struct SortCoordinateData | SortCoordinateData |
typedef struct SortCoordinateData * | SortCoordinate |
typedef struct TuplesortInstrumentation | TuplesortInstrumentation |
Enumerations | |
enum | TuplesortMethod { SORT_TYPE_STILL_IN_PROGRESS = 0 , SORT_TYPE_TOP_N_HEAPSORT = 1 << 0 , SORT_TYPE_QUICKSORT = 1 << 1 , SORT_TYPE_EXTERNAL_SORT = 1 << 2 , SORT_TYPE_EXTERNAL_MERGE = 1 << 3 } |
enum | TuplesortSpaceType { SORT_SPACE_TYPE_DISK , SORT_SPACE_TYPE_MEMORY } |
#define NUM_TUPLESORTMETHODS 4 |
Definition at line 81 of file tuplesort.h.
#define TUPLESORT_ALLOWBOUNDED (1 << 1) |
Definition at line 96 of file tuplesort.h.
#define TUPLESORT_NONE 0 |
Definition at line 90 of file tuplesort.h.
#define TUPLESORT_RANDOMACCESS (1 << 0) |
Definition at line 93 of file tuplesort.h.
typedef struct Sharedsort Sharedsort |
Definition at line 1 of file tuplesort.h.
typedef struct SortCoordinateData* SortCoordinate |
Definition at line 58 of file tuplesort.h.
typedef struct SortCoordinateData SortCoordinateData |
typedef struct TuplesortInstrumentation TuplesortInstrumentation |
typedef struct Tuplesortstate Tuplesortstate |
Definition at line 1 of file tuplesort.h.
enum TuplesortMethod |
Enumerator | |
---|---|
SORT_TYPE_STILL_IN_PROGRESS | |
SORT_TYPE_TOP_N_HEAPSORT | |
SORT_TYPE_QUICKSORT | |
SORT_TYPE_EXTERNAL_SORT | |
SORT_TYPE_EXTERNAL_MERGE |
Definition at line 72 of file tuplesort.h.
enum TuplesortSpaceType |
void tuplesort_attach_shared | ( | Sharedsort * | shared, |
dsm_segment * | seg | ||
) |
Definition at line 4721 of file tuplesort.c.
References Sharedsort::fileset, and SharedFileSetAttach().
Referenced by _bt_parallel_build_main().
Tuplesortstate* tuplesort_begin_cluster | ( | TupleDesc | tupDesc, |
Relation | indexRel, | ||
int | workMem, | ||
SortCoordinate | coordinate, | ||
int | sortopt | ||
) |
Definition at line 1105 of file tuplesort.c.
References _bt_mkscankey(), SortSupportData::abbreviate, Assert(), AssertState, BTGreaterStrategyNumber, BTLessStrategyNumber, BuildIndexInfo(), CLUSTER_SORT, comparetup_cluster(), copytup_cluster(), CreateExecutorState(), CurrentMemoryContext, ExprContext::ecxt_scantuple, elog, GetPerTupleExprContext, i, IndexRelationGetNumberOfKeyAttributes, LOG, MakeSingleTupleTableSlot(), MemoryContextSwitchTo(), palloc0(), PARALLEL_SORT, pfree(), PrepareSortSupportFromIndexRel(), RelationData::rd_rel, readtup_cluster(), RelationGetNumberOfAttributes, BTScanInsertData::scankeys, ScanKeyData::sk_attno, SK_BT_DESC, SK_BT_NULLS_FIRST, ScanKeyData::sk_collation, ScanKeyData::sk_flags, SortSupportData::ssup_attno, SortSupportData::ssup_collation, SortSupportData::ssup_cxt, SortSupportData::ssup_nulls_first, trace_sort, TTSOpsHeapTuple, tuplesort_begin_common(), TUPLESORT_RANDOMACCESS, and writetup_cluster().
Referenced by heapam_relation_copy_for_cluster().
Tuplesortstate* tuplesort_begin_datum | ( | Oid | datumType, |
Oid | sortOperator, | ||
Oid | sortCollation, | ||
bool | nullsFirstFlag, | ||
int | workMem, | ||
SortCoordinate | coordinate, | ||
int | sortopt | ||
) |
Definition at line 1396 of file tuplesort.c.
References comparetup_datum(), copytup_datum(), CurrentMemoryContext, DATUM_SORT, elog, get_typlenbyval(), LOG, MemoryContextSwitchTo(), palloc0(), PARALLEL_SORT, PrepareSortSupportFromOrderingOp(), readtup_datum(), trace_sort, tuplesort_begin_common(), TUPLESORT_RANDOMACCESS, and writetup_datum().
Referenced by ExecSort(), initialize_aggregate(), ordered_set_startup(), and validate_index().
Tuplesortstate* tuplesort_begin_heap | ( | TupleDesc | tupDesc, |
int | nkeys, | ||
AttrNumber * | attNums, | ||
Oid * | sortOperators, | ||
Oid * | sortCollations, | ||
bool * | nullsFirstFlags, | ||
int | workMem, | ||
SortCoordinate | coordinate, | ||
int | sortopt | ||
) |
Definition at line 1030 of file tuplesort.c.
References SortSupportData::abbreviate, AssertArg, comparetup_heap(), copytup_heap(), CurrentMemoryContext, elog, HEAP_SORT, i, LOG, MemoryContextSwitchTo(), palloc0(), PARALLEL_SORT, PrepareSortSupportFromOrderingOp(), readtup_heap(), SortSupportData::ssup_attno, SortSupportData::ssup_collation, SortSupportData::ssup_cxt, SortSupportData::ssup_nulls_first, trace_sort, tuplesort_begin_common(), TUPLESORT_RANDOMACCESS, and writetup_heap().
Referenced by ExecIncrementalSort(), ExecSort(), initialize_aggregate(), initialize_phase(), ordered_set_startup(), and switchToPresortedPrefixMode().
Tuplesortstate* tuplesort_begin_index_btree | ( | Relation | heapRel, |
Relation | indexRel, | ||
bool | enforceUnique, | ||
bool | uniqueNullsNotDistinct, | ||
int | workMem, | ||
SortCoordinate | coordinate, | ||
int | sortopt | ||
) |
Definition at line 1209 of file tuplesort.c.
References _bt_mkscankey(), SortSupportData::abbreviate, AssertState, BTGreaterStrategyNumber, BTLessStrategyNumber, comparetup_index_btree(), copytup_index(), CurrentMemoryContext, elog, i, INDEX_SORT, IndexRelationGetNumberOfKeyAttributes, LOG, MemoryContextSwitchTo(), palloc0(), PARALLEL_SORT, pfree(), PrepareSortSupportFromIndexRel(), readtup_index(), BTScanInsertData::scankeys, ScanKeyData::sk_attno, SK_BT_DESC, SK_BT_NULLS_FIRST, ScanKeyData::sk_collation, ScanKeyData::sk_flags, SortSupportData::ssup_attno, SortSupportData::ssup_collation, SortSupportData::ssup_cxt, SortSupportData::ssup_nulls_first, trace_sort, tuplesort_begin_common(), TUPLESORT_RANDOMACCESS, and writetup_index().
Referenced by _bt_parallel_scan_and_sort(), and _bt_spools_heapscan().
Tuplesortstate* tuplesort_begin_index_gist | ( | Relation | heapRel, |
Relation | indexRel, | ||
int | workMem, | ||
SortCoordinate | coordinate, | ||
int | sortopt | ||
) |
Definition at line 1338 of file tuplesort.c.
References SortSupportData::abbreviate, AssertState, comparetup_index_btree(), copytup_index(), CurrentMemoryContext, elog, i, IndexRelationGetNumberOfKeyAttributes, LOG, MemoryContextSwitchTo(), palloc0(), PrepareSortSupportFromGistIndexRel(), RelationData::rd_indcollation, readtup_index(), SortSupportData::ssup_attno, SortSupportData::ssup_collation, SortSupportData::ssup_cxt, SortSupportData::ssup_nulls_first, trace_sort, tuplesort_begin_common(), TUPLESORT_RANDOMACCESS, and writetup_index().
Referenced by gistbuild().
Tuplesortstate* tuplesort_begin_index_hash | ( | Relation | heapRel, |
Relation | indexRel, | ||
uint32 | high_mask, | ||
uint32 | low_mask, | ||
uint32 | max_buckets, | ||
int | workMem, | ||
SortCoordinate | coordinate, | ||
int | sortopt | ||
) |
Definition at line 1290 of file tuplesort.c.
References comparetup_index_hash(), copytup_index(), elog, LOG, MemoryContextSwitchTo(), readtup_index(), trace_sort, tuplesort_begin_common(), TUPLESORT_RANDOMACCESS, and writetup_index().
Referenced by _h_spoolinit().
void tuplesort_end | ( | Tuplesortstate * | state | ) |
Definition at line 1620 of file tuplesort.c.
References MemoryContextDelete(), and tuplesort_free().
Referenced by _bt_parallel_scan_and_sort(), _bt_spooldestroy(), _h_spooldestroy(), ExecEndAgg(), ExecEndIncrementalSort(), ExecEndSort(), ExecReScanAgg(), ExecReScanSort(), gistbuild(), heapam_relation_copy_for_cluster(), initialize_aggregate(), initialize_phase(), ordered_set_shutdown(), process_ordered_aggregate_multi(), process_ordered_aggregate_single(), and validate_index().
Size tuplesort_estimate_shared | ( | int | nworkers | ) |
Definition at line 4677 of file tuplesort.c.
References add_size(), Assert(), MAXALIGN, mul_size(), and offsetof.
Referenced by _bt_begin_parallel().
void tuplesort_get_stats | ( | Tuplesortstate * | state, |
TuplesortInstrumentation * | stats | ||
) |
Definition at line 3476 of file tuplesort.c.
References SORT_SPACE_TYPE_DISK, SORT_SPACE_TYPE_MEMORY, SORT_TYPE_EXTERNAL_MERGE, SORT_TYPE_EXTERNAL_SORT, SORT_TYPE_QUICKSORT, SORT_TYPE_STILL_IN_PROGRESS, SORT_TYPE_TOP_N_HEAPSORT, TuplesortInstrumentation::sortMethod, TuplesortInstrumentation::spaceType, TuplesortInstrumentation::spaceUsed, TSS_FINALMERGE, TSS_SORTEDINMEM, TSS_SORTEDONTAPE, and tuplesort_updatemax().
Referenced by ExecSort(), instrumentSortedGroup(), and show_sort_info().
bool tuplesort_getdatum | ( | Tuplesortstate * | state, |
bool | forward, | ||
Datum * | val, | ||
bool * | isNull, | ||
Datum * | abbrev | ||
) |
Definition at line 2647 of file tuplesort.c.
References SortTuple::datum1, datumCopy(), SortTuple::isnull1, MemoryContextSwitchTo(), PointerGetDatum, SortTuple::tuple, tuplesort_gettuple_common(), and val.
Referenced by ExecSort(), heapam_index_validate_scan(), mode_final(), percentile_cont_final_common(), percentile_cont_multi_final_common(), percentile_disc_final(), percentile_disc_multi_final(), and process_ordered_aggregate_single().
HeapTuple tuplesort_getheaptuple | ( | Tuplesortstate * | state, |
bool | forward | ||
) |
Definition at line 2598 of file tuplesort.c.
References MemoryContextSwitchTo(), SortTuple::tuple, and tuplesort_gettuple_common().
Referenced by heapam_relation_copy_for_cluster().
IndexTuple tuplesort_getindextuple | ( | Tuplesortstate * | state, |
bool | forward | ||
) |
Definition at line 2618 of file tuplesort.c.
References MemoryContextSwitchTo(), SortTuple::tuple, and tuplesort_gettuple_common().
Referenced by _bt_load(), _h_indexbuild(), and gist_indexsortbuild().
bool tuplesort_gettupleslot | ( | Tuplesortstate * | state, |
bool | forward, | ||
bool | copy, | ||
TupleTableSlot * | slot, | ||
Datum * | abbrev | ||
) |
Definition at line 2561 of file tuplesort.c.
References SortTuple::datum1, ExecClearTuple(), ExecStoreMinimalTuple(), heap_copy_minimal_tuple(), MemoryContextSwitchTo(), SortTuple::tuple, and tuplesort_gettuple_common().
Referenced by ExecIncrementalSort(), ExecSort(), fetch_input_tuple(), hypothetical_dense_rank_final(), hypothetical_rank_common(), process_ordered_aggregate_multi(), and switchToPresortedPrefixMode().
void tuplesort_initialize_shared | ( | Sharedsort * | shared, |
int | nWorkers, | ||
dsm_segment * | seg | ||
) |
Definition at line 4698 of file tuplesort.c.
References Assert(), Sharedsort::currentWorker, Sharedsort::fileset, TapeShare::firstblocknumber, i, Sharedsort::mutex, Sharedsort::nTapes, SharedFileSetInit(), SpinLockInit, Sharedsort::tapes, and Sharedsort::workersFinished.
Referenced by _bt_begin_parallel().
void tuplesort_markpos | ( | Tuplesortstate * | state | ) |
Definition at line 3412 of file tuplesort.c.
References Assert(), elog, ERROR, LogicalTapeTell(), MemoryContextSwitchTo(), TSS_SORTEDINMEM, TSS_SORTEDONTAPE, and TUPLESORT_RANDOMACCESS.
Referenced by ExecSortMarkPos().
int tuplesort_merge_order | ( | int64 | allowedMem | ) |
Definition at line 2755 of file tuplesort.c.
References Max, MAXORDER, MERGE_BUFFER_SIZE, Min, MINORDER, and TAPE_BUFFER_OVERHEAD.
Referenced by cost_tuplesort(), and inittapes().
const char* tuplesort_method_name | ( | TuplesortMethod | m | ) |
Definition at line 3520 of file tuplesort.c.
References SORT_TYPE_EXTERNAL_MERGE, SORT_TYPE_EXTERNAL_SORT, SORT_TYPE_QUICKSORT, SORT_TYPE_STILL_IN_PROGRESS, and SORT_TYPE_TOP_N_HEAPSORT.
Referenced by show_incremental_sort_group_info(), and show_sort_info().
void tuplesort_performsort | ( | Tuplesortstate * | state | ) |
Definition at line 2196 of file tuplesort.c.
References dumptuples(), elog, ERROR, inittapes(), leader_takeover_tapes(), LOG, MemoryContextSwitchTo(), mergeruns(), pg_rusage_show(), SERIAL, sort_bounded_heap(), trace_sort, TSS_BOUNDED, TSS_BUILDRUNS, TSS_FINALMERGE, TSS_INITIAL, TSS_SORTEDINMEM, TSS_SORTEDONTAPE, tuplesort_sort_memtuples(), WORKER, and worker_nomergeruns().
Referenced by _bt_leafbuild(), _bt_parallel_scan_and_sort(), _h_indexbuild(), ExecIncrementalSort(), ExecSort(), gistbuild(), heapam_relation_copy_for_cluster(), hypothetical_dense_rank_final(), hypothetical_rank_common(), initialize_phase(), mode_final(), percentile_cont_final_common(), percentile_cont_multi_final_common(), percentile_disc_final(), percentile_disc_multi_final(), process_ordered_aggregate_multi(), process_ordered_aggregate_single(), switchToPresortedPrefixMode(), and validate_index().
void tuplesort_putdatum | ( | Tuplesortstate * | state, |
Datum | val, | ||
bool | isNull | ||
) |
Definition at line 1961 of file tuplesort.c.
References consider_abort_common(), SortTuple::datum1, datumCopy(), DatumGetPointer, GetMemoryChunkSpace(), i, SortTuple::isnull1, MemoryContextSwitchTo(), PointerGetDatum, puttuple_common(), SortTuple::tuple, USEMEM, and val.
Referenced by ExecEvalAggOrderedTransDatum(), ExecSort(), ordered_set_transition(), and validate_index_callback().
void tuplesort_putheaptuple | ( | Tuplesortstate * | state, |
HeapTuple | tup | ||
) |
Definition at line 1862 of file tuplesort.c.
References COPYTUP, MemoryContextSwitchTo(), and puttuple_common().
Referenced by heapam_relation_copy_for_cluster().
void tuplesort_putindextuplevalues | ( | Tuplesortstate * | state, |
Relation | rel, | ||
ItemPointer | self, | ||
Datum * | values, | ||
bool * | isnull | ||
) |
Definition at line 1883 of file tuplesort.c.
References consider_abort_common(), SortTuple::datum1, GetMemoryChunkSpace(), i, index_form_tuple(), index_getattr, SortTuple::isnull1, MemoryContextSwitchTo(), puttuple_common(), RelationGetDescr, IndexTupleData::t_tid, SortTuple::tuple, USEMEM, and values.
Referenced by _bt_spool(), _h_spool(), and gistSortedBuildCallback().
void tuplesort_puttupleslot | ( | Tuplesortstate * | state, |
TupleTableSlot * | slot | ||
) |
Definition at line 1840 of file tuplesort.c.
References COPYTUP, MemoryContextSwitchTo(), and puttuple_common().
Referenced by ExecEvalAggOrderedTransTuple(), ExecIncrementalSort(), ExecSort(), fetch_input_tuple(), hypothetical_dense_rank_final(), hypothetical_rank_common(), ordered_set_transition_multi(), and switchToPresortedPrefixMode().
void tuplesort_rescan | ( | Tuplesortstate * | state | ) |
Definition at line 3379 of file tuplesort.c.
References Assert(), elog, ERROR, LogicalTapeRewindForRead(), MemoryContextSwitchTo(), TSS_SORTEDINMEM, TSS_SORTEDONTAPE, and TUPLESORT_RANDOMACCESS.
Referenced by ExecReScanSort(), mode_final(), percentile_cont_final_common(), percentile_cont_multi_final_common(), percentile_disc_final(), and percentile_disc_multi_final().
void tuplesort_reset | ( | Tuplesortstate * | state | ) |
Definition at line 1688 of file tuplesort.c.
References tuplesort_begin_batch(), tuplesort_free(), and tuplesort_updatemax().
Referenced by ExecIncrementalSort(), ExecReScanIncrementalSort(), and switchToPresortedPrefixMode().
void tuplesort_restorepos | ( | Tuplesortstate * | state | ) |
Definition at line 3443 of file tuplesort.c.
References Assert(), elog, ERROR, LogicalTapeSeek(), MemoryContextSwitchTo(), TSS_SORTEDINMEM, TSS_SORTEDONTAPE, and TUPLESORT_RANDOMACCESS.
Referenced by ExecSortRestrPos().
void tuplesort_set_bound | ( | Tuplesortstate * | state, |
int64 | bound | ||
) |
Definition at line 1484 of file tuplesort.c.
References Assert(), LEADER, TSS_INITIAL, TUPLESORT_ALLOWBOUNDED, and WORKER.
Referenced by ExecIncrementalSort(), ExecSort(), and switchToPresortedPrefixMode().
bool tuplesort_skiptuples | ( | Tuplesortstate * | state, |
int64 | ntuples, | ||
bool | forward | ||
) |
Definition at line 2687 of file tuplesort.c.
References Assert(), CHECK_FOR_INTERRUPTS, elog, ERROR, MemoryContextSwitchTo(), TSS_FINALMERGE, TSS_SORTEDINMEM, TSS_SORTEDONTAPE, tuplesort_gettuple_common(), and WORKER.
Referenced by percentile_cont_final_common(), percentile_cont_multi_final_common(), percentile_disc_final(), and percentile_disc_multi_final().
const char* tuplesort_space_type_name | ( | TuplesortSpaceType | t | ) |
Definition at line 3543 of file tuplesort.c.
References Assert(), SORT_SPACE_TYPE_DISK, and SORT_SPACE_TYPE_MEMORY.
Referenced by show_incremental_sort_group_info(), and show_sort_info().
bool tuplesort_used_bound | ( | Tuplesortstate * | state | ) |
Definition at line 1532 of file tuplesort.c.
Referenced by ExecIncrementalSort().