diff options
| author | David Rowley | 2024-04-07 12:32:26 +0000 |
|---|---|---|
| committer | David Rowley | 2024-04-07 12:32:26 +0000 |
| commit | 6ed83d5fa55cf6e6c9d1be34ec10730c48eba763 (patch) | |
| tree | c68c1b26f5e401bb8a24f471d72786a6c49103d9 /src/include | |
| parent | f3ff7bf83bce11709add9a6d31d4bebe95e086e3 (diff) | |
Use bump memory context for tuplesorts
29f6a959c added a bump allocator type for efficient compact allocations.
Here we make use of this for non-bounded tuplesorts to store tuples.
This is very space efficient when storing narrow tuples due to bump.c
not having chunk headers. This means we can fit more tuples in work_mem
before spilling to disk, or perform an in-memory sort touching fewer
cacheline.
Author: David Rowley
Reviewed-by: Nathan Bossart
Reviewed-by: Matthias van de Meent
Reviewed-by: Tomas Vondra
Reviewed-by: John Naylor
Discussion: https://postgr.es/m/CAApHDvqGSpCU95TmM=Bp=6xjL_nLys4zdZOpfNyWBk97Xrdj2w@mail.gmail.com
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/utils/tuplesort.h | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/include/utils/tuplesort.h b/src/include/utils/tuplesort.h index 1013c64dab4..e7941a1f09f 100644 --- a/src/include/utils/tuplesort.h +++ b/src/include/utils/tuplesort.h @@ -98,6 +98,15 @@ typedef enum /* specifies if the tuplesort is able to support bounded sorts */ #define TUPLESORT_ALLOWBOUNDED (1 << 1) +/* + * For bounded sort, tuples get pfree'd when they fall outside of the bound. + * When bounded sorts are not required, we can use a bump context for tuple + * allocation as there's no risk that pfree will ever be called for a tuple. + * Define a macro to make it easier for code to figure out if we're using a + * bump allocator. + */ +#define TupleSortUseBumpTupleCxt(opt) (((opt) & TUPLESORT_ALLOWBOUNDED) == 0) + typedef struct TuplesortInstrumentation { TuplesortMethod sortMethod; /* sort algorithm used */ @@ -109,10 +118,11 @@ typedef struct TuplesortInstrumentation * The objects we actually sort are SortTuple structs. These contain * a pointer to the tuple proper (might be a MinimalTuple or IndexTuple), * which is a separate palloc chunk --- we assume it is just one chunk and - * can be freed by a simple pfree() (except during merge, when we use a - * simple slab allocator). SortTuples also contain the tuple's first key - * column in Datum/nullflag format, and a source/input tape number that - * tracks which tape each heap element/slot belongs to during merging. + * can be freed by a simple pfree() (except during merge, where we use a + * simple slab allocator, and during a non-bounded sort where we use a bump + * allocator). SortTuples also contain the tuple's first key column in + * Datum/nullflag format, and a source/input tape number that tracks which + * tape each heap element/slot belongs to during merging. * * Storing the first key column lets us save heap_getattr or index_getattr * calls during tuple comparisons. We could extract and save all the key @@ -367,7 +377,8 @@ extern Tuplesortstate *tuplesort_begin_common(int workMem, extern void tuplesort_set_bound(Tuplesortstate *state, int64 bound); extern bool tuplesort_used_bound(Tuplesortstate *state); extern void tuplesort_puttuple_common(Tuplesortstate *state, - SortTuple *tuple, bool useAbbrev); + SortTuple *tuple, bool useAbbrev, + Size tuplen); extern void tuplesort_performsort(Tuplesortstate *state); extern bool tuplesort_gettuple_common(Tuplesortstate *state, bool forward, SortTuple *stup); |
