PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <limits.h>
#include "access/hash.h"
#include "access/htup_details.h"
#include "access/nbtree.h"
#include "catalog/index.h"
#include "catalog/pg_am.h"
#include "commands/tablespace.h"
#include "executor/executor.h"
#include "miscadmin.h"
#include "pg_trace.h"
#include "utils/datum.h"
#include "utils/logtape.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/pg_rusage.h"
#include "utils/rel.h"
#include "utils/sortsupport.h"
#include "utils/tuplesort.h"
#include "lib/sort_template.h"
Go to the source code of this file.
Data Structures | |
struct | SortTuple |
union | SlabSlot |
struct | Tuplesortstate |
struct | Sharedsort |
Macros | |
#define | HEAP_SORT 0 |
#define | INDEX_SORT 1 |
#define | DATUM_SORT 2 |
#define | CLUSTER_SORT 3 |
#define | PARALLEL_SORT(state) |
#define | INITIAL_MEMTUPSIZE |
#define | SLAB_SLOT_SIZE 1024 |
#define | MINORDER 6 /* minimum merge order */ |
#define | MAXORDER 500 /* maximum merge order */ |
#define | TAPE_BUFFER_OVERHEAD BLCKSZ |
#define | MERGE_BUFFER_SIZE (BLCKSZ * 32) |
#define | IS_SLAB_SLOT(state, tuple) |
#define | RELEASE_SLAB_SLOT(state, tuple) |
#define | COMPARETUP(state, a, b) ((*(state)->comparetup) (a, b, state)) |
#define | COPYTUP(state, stup, tup) ((*(state)->copytup) (state, stup, tup)) |
#define | WRITETUP(state, tape, stup) ((*(state)->writetup) (state, tape, stup)) |
#define | READTUP(state, stup, tape, len) ((*(state)->readtup) (state, stup, tape, len)) |
#define | LACKMEM(state) ((state)->availMem < 0 && !(state)->slabAllocatorUsed) |
#define | USEMEM(state, amt) ((state)->availMem -= (amt)) |
#define | FREEMEM(state, amt) ((state)->availMem += (amt)) |
#define | SERIAL(state) ((state)->shared == NULL) |
#define | WORKER(state) ((state)->shared && (state)->worker != -1) |
#define | LEADER(state) ((state)->shared && (state)->worker == -1) |
#define | LogicalTapeReadExact(tape, ptr, len) |
#define | ST_SORT qsort_tuple_unsigned |
#define | ST_ELEMENT_TYPE SortTuple |
#define | ST_COMPARE(a, b, state) qsort_tuple_unsigned_compare(a, b, state) |
#define | ST_COMPARE_ARG_TYPE Tuplesortstate |
#define | ST_CHECK_FOR_INTERRUPTS |
#define | ST_SCOPE static |
#define | ST_DEFINE |
#define | ST_SORT qsort_tuple_int32 |
#define | ST_ELEMENT_TYPE SortTuple |
#define | ST_COMPARE(a, b, state) qsort_tuple_int32_compare(a, b, state) |
#define | ST_COMPARE_ARG_TYPE Tuplesortstate |
#define | ST_CHECK_FOR_INTERRUPTS |
#define | ST_SCOPE static |
#define | ST_DEFINE |
#define | ST_SORT qsort_tuple |
#define | ST_ELEMENT_TYPE SortTuple |
#define | ST_COMPARE_RUNTIME_POINTER |
#define | ST_COMPARE_ARG_TYPE Tuplesortstate |
#define | ST_CHECK_FOR_INTERRUPTS |
#define | ST_SCOPE static |
#define | ST_DECLARE |
#define | ST_DEFINE |
#define | ST_SORT qsort_ssup |
#define | ST_ELEMENT_TYPE SortTuple |
#define | ST_COMPARE(a, b, ssup) |
#define | ST_COMPARE_ARG_TYPE SortSupportData |
#define | ST_CHECK_FOR_INTERRUPTS |
#define | ST_SCOPE static |
#define | ST_DEFINE |
Typedefs | |
typedef union SlabSlot | SlabSlot |
typedef int(* | SortTupleComparator) (const SortTuple *a, const SortTuple *b, Tuplesortstate *state) |
Enumerations | |
enum | TupSortStatus { TSS_INITIAL , TSS_BOUNDED , TSS_BUILDRUNS , TSS_SORTEDINMEM , TSS_SORTEDONTAPE , TSS_FINALMERGE } |
Variables | |
bool | trace_sort = false |
#define CLUSTER_SORT 3 |
Definition at line 126 of file tuplesort.c.
Definition at line 551 of file tuplesort.c.
Definition at line 552 of file tuplesort.c.
#define DATUM_SORT 2 |
Definition at line 125 of file tuplesort.c.
Definition at line 557 of file tuplesort.c.
#define HEAP_SORT 0 |
Definition at line 123 of file tuplesort.c.
#define INDEX_SORT 1 |
Definition at line 124 of file tuplesort.c.
#define INITIAL_MEMTUPSIZE |
Definition at line 139 of file tuplesort.c.
#define IS_SLAB_SLOT | ( | state, | |
tuple | |||
) |
Definition at line 531 of file tuplesort.c.
Definition at line 555 of file tuplesort.c.
Definition at line 560 of file tuplesort.c.
#define LogicalTapeReadExact | ( | tape, | |
ptr, | |||
len | |||
) |
Definition at line 612 of file tuplesort.c.
#define MAXORDER 500 /* maximum merge order */ |
Definition at line 235 of file tuplesort.c.
#define MERGE_BUFFER_SIZE (BLCKSZ * 32) |
Definition at line 237 of file tuplesort.c.
#define MINORDER 6 /* minimum merge order */ |
Definition at line 234 of file tuplesort.c.
#define PARALLEL_SORT | ( | state | ) |
Definition at line 129 of file tuplesort.c.
Definition at line 554 of file tuplesort.c.
#define RELEASE_SLAB_SLOT | ( | state, | |
tuple | |||
) |
Definition at line 539 of file tuplesort.c.
Definition at line 558 of file tuplesort.c.
#define SLAB_SLOT_SIZE 1024 |
Definition at line 200 of file tuplesort.c.
#define ST_CHECK_FOR_INTERRUPTS |
Definition at line 820 of file tuplesort.c.
#define ST_CHECK_FOR_INTERRUPTS |
Definition at line 820 of file tuplesort.c.
#define ST_CHECK_FOR_INTERRUPTS |
Definition at line 820 of file tuplesort.c.
#define ST_CHECK_FOR_INTERRUPTS |
Definition at line 820 of file tuplesort.c.
Definition at line 816 of file tuplesort.c.
Definition at line 816 of file tuplesort.c.
Definition at line 816 of file tuplesort.c.
#define ST_COMPARE_ARG_TYPE Tuplesortstate |
Definition at line 819 of file tuplesort.c.
#define ST_COMPARE_ARG_TYPE Tuplesortstate |
Definition at line 819 of file tuplesort.c.
#define ST_COMPARE_ARG_TYPE Tuplesortstate |
Definition at line 819 of file tuplesort.c.
#define ST_COMPARE_ARG_TYPE SortSupportData |
Definition at line 819 of file tuplesort.c.
#define ST_COMPARE_RUNTIME_POINTER |
Definition at line 806 of file tuplesort.c.
#define ST_DECLARE |
Definition at line 810 of file tuplesort.c.
#define ST_DEFINE |
Definition at line 822 of file tuplesort.c.
#define ST_DEFINE |
Definition at line 822 of file tuplesort.c.
#define ST_DEFINE |
Definition at line 822 of file tuplesort.c.
#define ST_DEFINE |
Definition at line 822 of file tuplesort.c.
#define ST_ELEMENT_TYPE SortTuple |
Definition at line 815 of file tuplesort.c.
#define ST_ELEMENT_TYPE SortTuple |
Definition at line 815 of file tuplesort.c.
#define ST_ELEMENT_TYPE SortTuple |
Definition at line 815 of file tuplesort.c.
#define ST_ELEMENT_TYPE SortTuple |
Definition at line 815 of file tuplesort.c.
#define ST_SCOPE static |
Definition at line 821 of file tuplesort.c.
#define ST_SCOPE static |
Definition at line 821 of file tuplesort.c.
#define ST_SCOPE static |
Definition at line 821 of file tuplesort.c.
#define ST_SCOPE static |
Definition at line 821 of file tuplesort.c.
#define ST_SORT qsort_tuple_unsigned |
Definition at line 814 of file tuplesort.c.
#define ST_SORT qsort_tuple_int32 |
Definition at line 814 of file tuplesort.c.
#define ST_SORT qsort_tuple |
Definition at line 814 of file tuplesort.c.
#define ST_SORT qsort_ssup |
Definition at line 814 of file tuplesort.c.
#define TAPE_BUFFER_OVERHEAD BLCKSZ |
Definition at line 236 of file tuplesort.c.
Definition at line 556 of file tuplesort.c.
Definition at line 559 of file tuplesort.c.
Definition at line 553 of file tuplesort.c.
Definition at line 239 of file tuplesort.c.
enum TupSortStatus |
Enumerator | |
---|---|
TSS_INITIAL | |
TSS_BOUNDED | |
TSS_BUILDRUNS | |
TSS_SORTEDINMEM | |
TSS_SORTEDONTAPE | |
TSS_FINALMERGE |
Definition at line 212 of file tuplesort.c.
|
static |
Definition at line 3241 of file tuplesort.c.
References Assert(), mergereadnext(), Min, SortTuple::srctape, and tuplesort_heap_insert().
Referenced by mergeonerun(), and mergeruns().
|
static |
Definition at line 4084 of file tuplesort.c.
References a, SortSupportData::abbrev_converter, ApplySortAbbrevFullComparator(), ApplySortComparator(), b, compare(), ExecStoreHeapTuple(), FormIndexDatum(), GetPerTupleExprContext, heap_getattr(), INDEX_MAX_KEYS, and ResetPerTupleExprContext.
Referenced by tuplesort_begin_cluster().
|
static |
Definition at line 4565 of file tuplesort.c.
References a, ApplySortAbbrevFullComparator(), ApplySortComparator(), b, compare(), and PointerGetDatum.
Referenced by tuplesort_begin_datum().
|
static |
Definition at line 3888 of file tuplesort.c.
References a, SortSupportData::abbrev_converter, ApplySortAbbrevFullComparator(), ApplySortComparator(), b, compare(), heap_getattr(), MINIMAL_TUPLE_OFFSET, SortSupportData::ssup_attno, HeapTupleData::t_data, and HeapTupleData::t_len.
Referenced by tuplesort_begin_heap().
|
static |
Definition at line 4326 of file tuplesort.c.
References a, SortSupportData::abbrev_converter, ApplySortAbbrevFullComparator(), ApplySortComparator(), Assert(), b, BuildIndexValueDescription(), compare(), ereport, errcode(), errdetail(), errmsg(), ERROR, errtableconstraint(), index_deform_tuple(), index_getattr, INDEX_MAX_KEYS, ItemPointerGetBlockNumber, ItemPointerGetOffsetNumber, RelationGetDescr, RelationGetRelationName, IndexTupleData::t_tid, and values.
Referenced by tuplesort_begin_index_btree(), and tuplesort_begin_index_gist().
|
static |
Definition at line 4460 of file tuplesort.c.
References _hash_hashkey2bucket(), a, Assert(), b, DatumGetUInt32, ItemPointerGetBlockNumber, ItemPointerGetOffsetNumber, and IndexTupleData::t_tid.
Referenced by tuplesort_begin_index_hash().
|
static |
Definition at line 2152 of file tuplesort.c.
References Assert(), and TSS_INITIAL.
Referenced by copytup_cluster(), copytup_heap(), tuplesort_putdatum(), and tuplesort_putindextuplevalues().
|
static |
Definition at line 4196 of file tuplesort.c.
References consider_abort_common(), SortTuple::datum1, GetMemoryChunkSpace(), heap_copytuple(), heap_getattr(), i, SortTuple::isnull1, MemoryContextSwitchTo(), SortTuple::tuple, and USEMEM.
Referenced by tuplesort_begin_cluster().
|
static |
Definition at line 4586 of file tuplesort.c.
Referenced by tuplesort_begin_datum().
|
static |
Definition at line 3950 of file tuplesort.c.
References consider_abort_common(), SortTuple::datum1, ExecCopySlotMinimalTuple(), GetMemoryChunkSpace(), heap_getattr(), i, SortTuple::isnull1, MemoryContextSwitchTo(), MINIMAL_TUPLE_OFFSET, HeapTupleData::t_data, HeapTupleData::t_len, MinimalTupleData::t_len, SortTuple::tuple, and USEMEM.
Referenced by tuplesort_begin_heap().
|
static |
Definition at line 4515 of file tuplesort.c.
Referenced by tuplesort_begin_index_btree(), tuplesort_begin_index_gist(), and tuplesort_begin_index_hash().
|
static |
Definition at line 3288 of file tuplesort.c.
References Assert(), elog(), ereport, errcode(), errmsg(), ERROR, i, LACKMEM, LOG, markrunend(), MemoryContextReset(), pg_rusage_show(), selectnewtape(), trace_sort, TSS_BUILDRUNS, tuplesort_sort_memtuples(), and WRITETUP.
Referenced by puttuple_common(), and tuplesort_performsort().
|
static |
Definition at line 4888 of file tuplesort.c.
References FREEMEM, GetMemoryChunkSpace(), pfree(), and SortTuple::tuple.
Referenced by make_bounded_heap(), and puttuple_common().
|
static |
Definition at line 3833 of file tuplesort.c.
References elog(), ERROR, len, and LogicalTapeRead().
Referenced by mergereadnext(), and tuplesort_gettuple_common().
|
static |
Definition at line 1721 of file tuplesort.c.
References elog(), ERROR, FREEMEM, GetMemoryChunkSpace(), LACKMEM, MaxAllocHugeSize, repalloc_huge(), and USEMEM.
Referenced by puttuple_common().
|
static |
Definition at line 2960 of file tuplesort.c.
References i, palloc(), SLAB_SLOT_SIZE, and USEMEM.
Referenced by mergeruns().
|
static |
Definition at line 2842 of file tuplesort.c.
References Assert(), elog(), inittapestate(), LEADER, LOG, LogicalTapeSetCreate(), mergeruns(), MINORDER, palloc0(), pg_rusage_show(), selectnewtape(), trace_sort, TSS_BUILDRUNS, tuplesort_merge_order(), and WORKER.
Referenced by puttuple_common(), and tuplesort_performsort().
|
static |
Definition at line 2893 of file tuplesort.c.
References GetMemoryChunkSpace(), PrepareTempTablespaces(), TAPE_BUFFER_OVERHEAD, and USEMEM.
Referenced by inittapes(), and leader_takeover_tapes().
|
static |
Definition at line 4829 of file tuplesort.c.
References Assert(), elog(), ERROR, Sharedsort::fileset, inittapestate(), j, LEADER, LogicalTapeImport(), LogicalTapeSetCreate(), Sharedsort::mutex, palloc0(), SpinLockAcquire, SpinLockRelease, Sharedsort::tapes, TSS_BUILDRUNS, and Sharedsort::workersFinished.
Referenced by tuplesort_performsort().
|
static |
Definition at line 3564 of file tuplesort.c.
References Assert(), CHECK_FOR_INTERRUPTS, COMPARETUP, free_sort_tuple(), i, reversedirection(), SERIAL, TSS_BOUNDED, TSS_INITIAL, tuplesort_heap_insert(), and tuplesort_heap_replace_top().
Referenced by puttuple_common().
|
static |
Definition at line 3846 of file tuplesort.c.
References len, and LogicalTapeWrite().
Referenced by dumptuples(), and mergeonerun().
|
static |
Definition at line 2810 of file tuplesort.c.
References Max, Min, and TAPE_BUFFER_OVERHEAD.
Referenced by mergeruns().
|
static |
Definition at line 3183 of file tuplesort.c.
References beginmerge(), markrunend(), mergereadnext(), RELEASE_SLAB_SLOT, SortTuple::srctape, tuplesort_heap_delete_top(), tuplesort_heap_replace_top(), and WRITETUP.
Referenced by mergeruns().
|
static |
Definition at line 3269 of file tuplesort.c.
References getlen(), and READTUP.
Referenced by beginmerge(), mergeonerun(), and tuplesort_gettuple_common().
|
static |
Definition at line 2996 of file tuplesort.c.
References Assert(), beginmerge(), elog(), FREEMEM, GetMemoryChunkSpace(), init_slab_allocator(), INT64_FORMAT, LOG, LogicalTapeClose(), LogicalTapeFreeze(), LogicalTapeRewindForRead(), LogicalTapeSetForgetFreeSpace(), MemoryContextAlloc(), MemoryContextResetOnly(), merge_read_buffer_size(), mergeonerun(), palloc0(), pfree(), pg_rusage_show(), selectnewtape(), trace_sort, TSS_BUILDRUNS, TSS_FINALMERGE, TSS_SORTEDONTAPE, TUPLESORT_RANDOMACCESS, USEMEM, WORKER, and worker_freeze_result_tape().
Referenced by inittapes(), and tuplesort_performsort().
|
static |
Definition at line 2043 of file tuplesort.c.
References Assert(), CHECK_FOR_INTERRUPTS, COMPARETUP, dumptuples(), elog(), ERROR, free_sort_tuple(), grow_memtuples(), inittapes(), LACKMEM, LEADER, LOG, make_bounded_heap(), pg_rusage_show(), trace_sort, TSS_BOUNDED, TSS_BUILDRUNS, TSS_INITIAL, and tuplesort_heap_replace_top().
Referenced by tuplesort_putdatum(), tuplesort_putheaptuple(), tuplesort_putindextuplevalues(), and tuplesort_puttupleslot().
|
static |
Definition at line 745 of file tuplesort.c.
References a, ApplyInt32SortComparator(), b, and compare().
|
static |
Definition at line 698 of file tuplesort.c.
References a, ApplyUnsignedSortComparator(), b, and compare().
|
static |
Definition at line 3860 of file tuplesort.c.
References Assert(), buf, MemoryContextAlloc(), and SLAB_SLOT_SIZE.
Referenced by readtup_cluster(), readtup_datum(), readtup_heap(), and readtup_index().
|
static |
Definition at line 4290 of file tuplesort.c.
References SortTuple::datum1, heap_getattr(), HEAPTUPLESIZE, InvalidOid, SortTuple::isnull1, LogicalTapeReadExact, readtup_alloc(), HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, HeapTupleData::t_tableOid, SortTuple::tuple, and TUPLESORT_RANDOMACCESS.
Referenced by tuplesort_begin_cluster().
|
static |
Definition at line 4632 of file tuplesort.c.
References Assert(), SortTuple::datum1, SortTuple::isnull1, len, LogicalTapeReadExact, PointerGetDatum, readtup_alloc(), SortTuple::tuple, and TUPLESORT_RANDOMACCESS.
Referenced by tuplesort_begin_datum().
|
static |
Definition at line 4053 of file tuplesort.c.
References SortTuple::datum1, heap_getattr(), SortTuple::isnull1, len, LogicalTapeReadExact, MINIMAL_TUPLE_DATA_OFFSET, MINIMAL_TUPLE_OFFSET, readtup_alloc(), HeapTupleData::t_data, HeapTupleData::t_len, MinimalTupleData::t_len, SortTuple::tuple, and TUPLESORT_RANDOMACCESS.
Referenced by tuplesort_begin_heap().
|
static |
Definition at line 4542 of file tuplesort.c.
References SortTuple::datum1, index_getattr, SortTuple::isnull1, len, LogicalTapeReadExact, readtup_alloc(), RelationGetDescr, SortTuple::tuple, and TUPLESORT_RANDOMACCESS.
Referenced by tuplesort_begin_index_btree(), tuplesort_begin_index_gist(), and tuplesort_begin_index_hash().
|
static |
Definition at line 3815 of file tuplesort.c.
References SortSupportData::ssup_nulls_first, and SortSupportData::ssup_reverse.
Referenced by make_bounded_heap(), and sort_bounded_heap().
|
static |
Definition at line 2927 of file tuplesort.c.
References Assert(), and LogicalTapeCreate().
Referenced by dumptuples(), inittapes(), and mergeruns().
|
static |
Definition at line 3613 of file tuplesort.c.
References Assert(), reversedirection(), SERIAL, TSS_BOUNDED, TSS_SORTEDINMEM, and tuplesort_heap_delete_top().
Referenced by tuplesort_performsort().
int ssup_datum_int32_cmp | ( | Datum | x, |
Datum | y, | ||
SortSupport | ssup | ||
) |
Definition at line 4926 of file tuplesort.c.
References DatumGetInt32, x, and y.
Referenced by btint4sortsupport(), date_sortsupport(), and tuplesort_sort_memtuples().
int ssup_datum_unsigned_cmp | ( | Datum | x, |
Datum | y, | ||
SortSupport | ssup | ||
) |
Definition at line 4899 of file tuplesort.c.
Referenced by gist_point_sortsupport(), macaddr_sortsupport(), network_sortsupport(), tuplesort_sort_memtuples(), uuid_sortsupport(), and varstr_sortsupport().
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().
|
static |
Definition at line 956 of file tuplesort.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, elog(), ERROR, GenerationContextCreate(), GetMemoryChunkSpace(), INITIAL_MEMTUPSIZE, LACKMEM, MemoryContextSwitchTo(), palloc(), pfree(), TSS_INITIAL, TUPLESORT_ALLOWBOUNDED, and USEMEM.
Referenced by tuplesort_begin_common(), and tuplesort_reset().
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().
|
static |
Definition at line 845 of file tuplesort.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert(), CurrentMemoryContext, elog(), ERROR, INITIAL_MEMTUPSIZE, SortCoordinateData::isWorker, Max, MemoryContextSwitchTo(), SortCoordinateData::nParticipants, palloc0(), pg_rusage_init(), SortCoordinateData::sharedsort, trace_sort, tuplesort_begin_batch(), TUPLESORT_RANDOMACCESS, and worker_get_identifier().
Referenced by tuplesort_begin_cluster(), tuplesort_begin_datum(), tuplesort_begin_heap(), tuplesort_begin_index_btree(), tuplesort_begin_index_gist(), and tuplesort_begin_index_hash().
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().
|
static |
Definition at line 1543 of file tuplesort.c.
References ExprContext::ecxt_scantuple, elog(), ExecDropSingleTupleTableSlot(), FreeExecutorState(), GetPerTupleExprContext, LOG, LogicalTapeSetBlocks(), LogicalTapeSetClose(), MemoryContextReset(), MemoryContextSwitchTo(), pg_rusage_show(), SERIAL, and trace_sort.
Referenced by tuplesort_end(), and tuplesort_reset().
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().
|
static |
Definition at line 2307 of file tuplesort.c.
References Assert(), elog(), ERROR, getlen(), LogicalTapeBackspace(), LogicalTapeClose(), mergereadnext(), READTUP, RELEASE_SLAB_SLOT, SortTuple::srctape, TSS_FINALMERGE, TSS_SORTEDINMEM, TSS_SORTEDONTAPE, SortTuple::tuple, tuplesort_heap_delete_top(), tuplesort_heap_replace_top(), TUPLESORT_RANDOMACCESS, and WORKER.
Referenced by tuplesort_getdatum(), tuplesort_getheaptuple(), tuplesort_getindextuple(), tuplesort_gettupleslot(), and tuplesort_skiptuples().
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().
|
static |
Definition at line 3751 of file tuplesort.c.
References tuplesort_heap_replace_top().
Referenced by mergeonerun(), sort_bounded_heap(), and tuplesort_gettuple_common().
|
static |
Definition at line 3716 of file tuplesort.c.
References Assert(), CHECK_FOR_INTERRUPTS, COMPARETUP, i, and j.
Referenced by beginmerge(), and make_bounded_heap().
|
static |
Definition at line 3775 of file tuplesort.c.
References Assert(), CHECK_FOR_INTERRUPTS, COMPARETUP, i, and j.
Referenced by make_bounded_heap(), mergeonerun(), puttuple_common(), tuplesort_gettuple_common(), and tuplesort_heap_delete_top().
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().
|
static |
Definition at line 3653 of file tuplesort.c.
References Assert(), LEADER, ssup_datum_int32_cmp(), and ssup_datum_unsigned_cmp().
Referenced by dumptuples(), and tuplesort_performsort().
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().
|
static |
Definition at line 1637 of file tuplesort.c.
References LogicalTapeSetBlocks().
Referenced by tuplesort_get_stats(), and tuplesort_reset().
bool tuplesort_used_bound | ( | Tuplesortstate * | state | ) |
Definition at line 1532 of file tuplesort.c.
Referenced by ExecIncrementalSort().
|
static |
Definition at line 4769 of file tuplesort.c.
References Assert(), LogicalTapeFreeze(), Sharedsort::mutex, output(), pfree(), SpinLockAcquire, SpinLockRelease, Sharedsort::tapes, WORKER, and Sharedsort::workersFinished.
Referenced by mergeruns(), and worker_nomergeruns().
|
static |
Definition at line 4741 of file tuplesort.c.
References Assert(), Sharedsort::currentWorker, Sharedsort::mutex, SpinLockAcquire, SpinLockRelease, and WORKER.
Referenced by tuplesort_begin_common().
|
static |
Definition at line 4807 of file tuplesort.c.
References Assert(), WORKER, and worker_freeze_result_tape().
Referenced by tuplesort_performsort().
|
static |
Definition at line 4269 of file tuplesort.c.
References FREEMEM, GetMemoryChunkSpace(), heap_freetuple(), LogicalTapeWrite(), HeapTupleData::t_data, HeapTupleData::t_len, HeapTupleData::t_self, SortTuple::tuple, and TUPLESORT_RANDOMACCESS.
Referenced by tuplesort_begin_cluster().
|
static |
Definition at line 4593 of file tuplesort.c.
References Assert(), SortTuple::datum1, datumGetSize(), FREEMEM, GetMemoryChunkSpace(), SortTuple::isnull1, LogicalTapeWrite(), pfree(), PointerGetDatum, SortTuple::tuple, and TUPLESORT_RANDOMACCESS.
Referenced by tuplesort_begin_datum().
|