Re: tuple radix sort

John Naylor <johncnaylorls@gmail.com>

From: John Naylor <johncnaylorls@gmail.com>
To: zengman <zengman@halodbtech.com>
Cc: pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-02-10T13:37:59Z
Lists: pgsql-hackers

Attachments

On Wed, Jan 21, 2026 at 1:40 PM John Naylor <johncnaylorls@gmail.com> wrote:
> Attached is v6, which seems pretty close to committable. The temporary
> GUC is gone, as are all the integer-like qsort specializations. There
> are a few cosmetic rearrangements, but the algorithm is pretty much
> the same as v5. The only visible behavior difference should be the
> addition of a presorted check just like qsort has.

I did some more self-review after a couple weeks and made some more
minor cosmetic adjustments for v7. I will commit 0001 and 0002 in a
few days unless there are objections.

> * The only things I have doubts about are the user-visible messages
> mentioning "qsort". For trace_sort, it seemed logical to re-use the
> term "internal sort" from other such messages, so I've done that for
> v6. EXPLAIN ANALYZE is a bit harder: Do we want to even change
> anything here? When things like this come up, there is the question of
> tools that parse the output. It doesn't seem particularly important to
> try to display exact info here, especially since radix sort must
> divert to qsort for multiple keys etc.

I decided to split this out to a separate patch, 0003. It doesn't seem
important, and may not be desirable after all. There is also a 0004
which is just verifying sort order in assert builds on the existing
qsort calls and not just the new sort. Looks better this way.

> Speaking of the NULL partitioning step, I've tried to add some
> comments that make sense, but the pictures in the linked blog are more
> helpful than any words I can come up with. It's easier to understand
> than to describe.

I tried to improve readability here and added missing CHECK_FOR_INTERRUPTS().

Also ran UB sanitizer and Valgrind.

On Wed, Jan 21, 2026 at 3:12 PM zengman <zengman@halodbtech.com> wrote:
> I wanted to point out a small detail: the line `extern PGDLLIMPORT bool wip_radix_sort;`
>  in v6-0001 appears to not have been fully cleaned up — I suspect it might have been overlooked.

Fixed as well.

--
John Naylor
Amazon Web Services

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