@@ -344,6 +344,12 @@ struct Tuplesortstate
344
344
TupleDesc tupDesc ;
345
345
SortSupport sortKeys ; /* array of length nKeys */
346
346
347
+ /*
348
+ * This variable is shared by the single-key MinimalTuple case and the
349
+ * Datum case. Otherwise it's NULL.
350
+ */
351
+ SortSupport onlyKey ;
352
+
347
353
/*
348
354
* These variables are specific to the CLUSTER case; they are set by
349
355
* tuplesort_begin_cluster. Note CLUSTER also uses tupDesc and
@@ -365,9 +371,6 @@ struct Tuplesortstate
365
371
/* These are specific to the index_hash subcase: */
366
372
uint32 hash_mask ; /* mask for sortable part of hash code */
367
373
368
- /* This is initialized when, and only when, there's just one key. */
369
- SortSupport onlyKey ;
370
-
371
374
/*
372
375
* These variables are specific to the Datum case; they are set by
373
376
* tuplesort_begin_datum and used only by the DatumTuple routines.
@@ -497,7 +500,8 @@ static void reversedirection_datum(Tuplesortstate *state);
497
500
static void free_sort_tuple (Tuplesortstate * state , SortTuple * stup );
498
501
499
502
/*
500
- * Special version of qsort, just for SortTuple objects.
503
+ * Special versions of qsort just for SortTuple objects. We have one for the
504
+ * single-key case (qsort_ssup) and one for multi-key cases (qsort_tuple).
501
505
*/
502
506
#include "qsort_tuple.c"
503
507
@@ -1236,6 +1240,7 @@ tuplesort_performsort(Tuplesortstate *state)
1236
1240
*/
1237
1241
if (state -> memtupcount > 1 )
1238
1242
{
1243
+ /* Can we use the single-key sort function? */
1239
1244
if (state -> onlyKey != NULL )
1240
1245
qsort_ssup (state -> memtuples , state -> memtupcount ,
1241
1246
state -> onlyKey );
@@ -3061,7 +3066,6 @@ comparetup_index_btree(const SortTuple *a, const SortTuple *b,
3061
3066
* they *must* get compared at some stage of the sort --- otherwise the
3062
3067
* sort algorithm wouldn't have checked whether one must appear before the
3063
3068
* other.
3064
- *
3065
3069
*/
3066
3070
if (state -> enforceUnique && !equal_hasnull )
3067
3071
{
@@ -3243,9 +3247,9 @@ reversedirection_index_hash(Tuplesortstate *state)
3243
3247
static int
3244
3248
comparetup_datum (const SortTuple * a , const SortTuple * b , Tuplesortstate * state )
3245
3249
{
3246
- /* Not currently needed */
3247
- elog ( ERROR , "comparetup_datum() should not be called" );
3248
- return 0 ;
3250
+ return ApplySortComparator ( a -> datum1 , a -> isnull1 ,
3251
+ b -> datum1 , b -> isnull1 ,
3252
+ state -> onlyKey ) ;
3249
3253
}
3250
3254
3251
3255
static void
0 commit comments