Skip to content

Commit 17b985b

Browse files
committed
Fix broken comparetup_datum code.
Commit 337b6f5 contained the entirely fanciful assumption that it had made comparetup_datum unreachable. Reported and patched by Takashi Yamamoto. Fix up some not terribly accurate/useful comments from that commit, too.
1 parent 6c41948 commit 17b985b

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/backend/utils/sort/tuplesort.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,12 @@ struct Tuplesortstate
344344
TupleDesc tupDesc;
345345
SortSupport sortKeys; /* array of length nKeys */
346346

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+
347353
/*
348354
* These variables are specific to the CLUSTER case; they are set by
349355
* tuplesort_begin_cluster. Note CLUSTER also uses tupDesc and
@@ -365,9 +371,6 @@ struct Tuplesortstate
365371
/* These are specific to the index_hash subcase: */
366372
uint32 hash_mask; /* mask for sortable part of hash code */
367373

368-
/* This is initialized when, and only when, there's just one key. */
369-
SortSupport onlyKey;
370-
371374
/*
372375
* These variables are specific to the Datum case; they are set by
373376
* tuplesort_begin_datum and used only by the DatumTuple routines.
@@ -497,7 +500,8 @@ static void reversedirection_datum(Tuplesortstate *state);
497500
static void free_sort_tuple(Tuplesortstate *state, SortTuple *stup);
498501

499502
/*
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).
501505
*/
502506
#include "qsort_tuple.c"
503507

@@ -1236,6 +1240,7 @@ tuplesort_performsort(Tuplesortstate *state)
12361240
*/
12371241
if (state->memtupcount > 1)
12381242
{
1243+
/* Can we use the single-key sort function? */
12391244
if (state->onlyKey != NULL)
12401245
qsort_ssup(state->memtuples, state->memtupcount,
12411246
state->onlyKey);
@@ -3061,7 +3066,6 @@ comparetup_index_btree(const SortTuple *a, const SortTuple *b,
30613066
* they *must* get compared at some stage of the sort --- otherwise the
30623067
* sort algorithm wouldn't have checked whether one must appear before the
30633068
* other.
3064-
*
30653069
*/
30663070
if (state->enforceUnique && !equal_hasnull)
30673071
{
@@ -3243,9 +3247,9 @@ reversedirection_index_hash(Tuplesortstate *state)
32433247
static int
32443248
comparetup_datum(const SortTuple *a, const SortTuple *b, Tuplesortstate *state)
32453249
{
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);
32493253
}
32503254

32513255
static void

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy