1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Rename tuplesort.c's SortTuple.tupindex field.

Rename the "tupindex" field from tuplesort.c's SortTuple struct to
"srctape", since it can only ever be used to store a source/input tape
number when merging external sort runs.  This has been the case since
commit 8b304b8b72, which removed replacement selection sort from
tuplesort.c.
This commit is contained in:
Peter Geoghegan
2019-08-09 17:06:45 -07:00
parent 0662eb6219
commit d8cd68c8d4

View File

@ -141,7 +141,8 @@ bool optimize_bounded_sort = true;
* which is a separate palloc chunk --- we assume it is just one chunk and * 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 * 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 * simple slab allocator). SortTuples also contain the tuple's first key
* column in Datum/nullflag format, and an index integer. * 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 * 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 * calls during tuple comparisons. We could extract and save all the key
@ -162,16 +163,13 @@ bool optimize_bounded_sort = true;
* either the same pointer as "tuple", or is an abbreviated key value as * either the same pointer as "tuple", or is an abbreviated key value as
* described above. Accordingly, "tuple" is always used in preference to * described above. Accordingly, "tuple" is always used in preference to
* datum1 as the authoritative value for pass-by-reference cases. * datum1 as the authoritative value for pass-by-reference cases.
*
* tupindex holds the input tape number that each tuple in the heap was read
* from during merge passes.
*/ */
typedef struct typedef struct
{ {
void *tuple; /* the tuple itself */ void *tuple; /* the tuple itself */
Datum datum1; /* value of first key column */ Datum datum1; /* value of first key column */
bool isnull1; /* is first key column NULL? */ bool isnull1; /* is first key column NULL? */
int tupindex; /* see notes above */ int srctape; /* source tape number */
} SortTuple; } SortTuple;
/* /*
@ -2093,7 +2091,7 @@ tuplesort_gettuple_common(Tuplesortstate *state, bool forward,
*/ */
if (state->memtupcount > 0) if (state->memtupcount > 0)
{ {
int srcTape = state->memtuples[0].tupindex; int srcTape = state->memtuples[0].srctape;
SortTuple newtup; SortTuple newtup;
*stup = state->memtuples[0]; *stup = state->memtuples[0];
@ -2124,7 +2122,7 @@ tuplesort_gettuple_common(Tuplesortstate *state, bool forward,
LogicalTapeRewindForWrite(state->tapeset, srcTape); LogicalTapeRewindForWrite(state->tapeset, srcTape);
return true; return true;
} }
newtup.tupindex = srcTape; newtup.srctape = srcTape;
tuplesort_heap_replace_top(state, &newtup); tuplesort_heap_replace_top(state, &newtup);
return true; return true;
} }
@ -2808,7 +2806,7 @@ mergeonerun(Tuplesortstate *state)
SortTuple stup; SortTuple stup;
/* write the tuple to destTape */ /* write the tuple to destTape */
srcTape = state->memtuples[0].tupindex; srcTape = state->memtuples[0].srctape;
WRITETUP(state, destTape, &state->memtuples[0]); WRITETUP(state, destTape, &state->memtuples[0]);
/* recycle the slot of the tuple we just wrote out, for the next read */ /* recycle the slot of the tuple we just wrote out, for the next read */
@ -2821,7 +2819,7 @@ mergeonerun(Tuplesortstate *state)
*/ */
if (mergereadnext(state, srcTape, &stup)) if (mergereadnext(state, srcTape, &stup))
{ {
stup.tupindex = srcTape; stup.srctape = srcTape;
tuplesort_heap_replace_top(state, &stup); tuplesort_heap_replace_top(state, &stup);
} }
else else
@ -2886,7 +2884,7 @@ beginmerge(Tuplesortstate *state)
if (mergereadnext(state, srcTape, &tup)) if (mergereadnext(state, srcTape, &tup))
{ {
tup.tupindex = srcTape; tup.srctape = srcTape;
tuplesort_heap_insert(state, &tup); tuplesort_heap_insert(state, &tup);
} }
} }