/* These are specific to the index_hash subcase: */
uint32 hash_mask; /* mask for sortable part of hash code */
+ /* This is initialized when, and only when, there's just one key. */
+ SortSupport onlyKey;
+
/*
* These variables are specific to the Datum case; they are set by
* tuplesort_begin_datum and used only by the DatumTuple routines.
*/
Oid datumType;
- SortSupport datumKey;
/* we need typelen and byval in order to know how to copy the Datums. */
int datumTypeLen;
bool datumTypeByVal;
PrepareSortSupportFromOrderingOp(sortOperators[i], sortKey);
}
+ if (nkeys == 1)
+ state->onlyKey = state->sortKeys;
+
MemoryContextSwitchTo(oldcontext);
return state;
state->datumType = datumType;
/* Prepare SortSupport data */
- state->datumKey = (SortSupport) palloc0(sizeof(SortSupportData));
+ state->onlyKey = (SortSupport) palloc0(sizeof(SortSupportData));
- state->datumKey->ssup_cxt = CurrentMemoryContext;
- state->datumKey->ssup_collation = sortCollation;
- state->datumKey->ssup_nulls_first = nullsFirstFlag;
+ state->onlyKey->ssup_cxt = CurrentMemoryContext;
+ state->onlyKey->ssup_collation = sortCollation;
+ state->onlyKey->ssup_nulls_first = nullsFirstFlag;
- PrepareSortSupportFromOrderingOp(sortOperator, state->datumKey);
+ PrepareSortSupportFromOrderingOp(sortOperator, state->onlyKey);
/* lookup necessary attributes of the datum type */
get_typlenbyval(datumType, &typlen, &typbyval);
*/
if (state->memtupcount > 1)
{
- if (state->comparetup == comparetup_heap && state->nKeys == 1)
+ if (state->onlyKey != NULL)
qsort_ssup(state->memtuples, state->memtupcount,
- state->sortKeys);
+ state->onlyKey);
else
qsort_tuple(state->memtuples,
state->memtupcount,
static int
comparetup_datum(const SortTuple *a, const SortTuple *b, Tuplesortstate *state)
{
- return ApplySortComparator(a->datum1, a->isnull1,
- b->datum1, b->isnull1,
- state->datumKey);
+ /* Not currently needed */
+ elog(ERROR, "comparetup_datum() should not be called");
+ return 0;
}
static void
static void
reversedirection_datum(Tuplesortstate *state)
{
- state->datumKey->ssup_reverse = !state->datumKey->ssup_reverse;
- state->datumKey->ssup_nulls_first = !state->datumKey->ssup_nulls_first;
+ state->onlyKey->ssup_reverse = !state->onlyKey->ssup_reverse;
+ state->onlyKey->ssup_nulls_first = !state->onlyKey->ssup_nulls_first;
}
/*