Re: tuple radix sort

cca5507 <cca5507@qq.com>

From: cca5507 <cca5507@qq.com>
To: John Naylor <johncnaylorls@gmail.com>
Cc: zengman <zengman@halodbtech.com>, pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-04-01T09:27:13Z
Lists: pgsql-hackers
Hi John,

How about adding an assertion here:

```
diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c
index 72c2c2995d8..bcc534136d7 100644
--- a/src/backend/utils/sort/tuplesort.c
+++ b/src/backend/utils/sort/tuplesort.c
@@ -2783,6 +2783,8 @@ radix_sort_recursive(SortTuple *begin, size_t n_elems, int level, Tuplesortstate
        else
                next_level = level + 1;
 
+       Assert(next_level > level);
+
        for (uint8 *rp = remaining_partitions;
                 rp < remaining_partitions + num_partitions;
                 rp++)
```

It can help us catch some unexpected behaviors.

--
Regards,
ChangAo Chen

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Cosmetic fixes for radix sort

  2. Skip common prefixes during radix sort

  3. Perform radix sort on SortTuples with pass-by-value Datums

  4. Grab the low-hanging fruit from forcing sizeof(Datum) to 8.

  5. Add missing Datum conversions