Re: tuple radix sort
John Naylor <johncnaylorls@gmail.com>
From: John Naylor <johncnaylorls@gmail.com>
To: cca5507 <cca5507@qq.com>
Cc: zengman <zengman@halodbtech.com>, pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-02-15T08:40:35Z
Lists: pgsql-hackers
Attachments
- v8-0004-WIP-Call-verify_memtuples_sorted-after-qsort-for-.patch (text/x-patch) patch v8-0004
- v8-0003-WIP-Add-possible-message-changes.patch (text/x-patch) patch v8-0003
- v8-0002-Detect-common-prefix-to-avoid-wasted-work-during-.patch (text/x-patch) patch v8-0002
I've committed v7-0001 with the above review and a couple more cosmetic adjustments. Most notably, I've never really liked the name sort_byvalue_datum(). It really is the entry point to radix sort, and it only diverts to qsort if after the NULL partitioning phase there aren't enough non-null tuples to justify the overhead of radix sort. So for better symmetry with qsort_tuple, I've renamed sort_byvalue_datum() to radix_sort_tuple(), which then calls out to now-named radix_sort_recursive(), which will call itself until it completes or diverts. Another change down below: On Fri, Feb 13, 2026 at 10:25 AM cca5507 <cca5507@qq.com> wrote: > I think we need to add a comment to explain why we do the > check. The cost of this check is not small. (presorted check) The cost should only matter for pathological inputs, and I haven't found it to matter much overall. I've left it uncommented for now. However, while rebasing 0002 to deal with recent review comments, I had an idea: In yesterday's commit, I moved the presorted check down to just before invoking the actual radix sort. That way, with the attached v8-0002 the common prefix detection is done at the same time as the presorted check. That makes 0002 a smaller patch and by doing both in the same for-loop it's easier to read and can reduce the number of memory reads. We can consider more commentary here, but the motivation do avoid unnecessary work should be fairly obvious. Next step : Test whether it's worth it for the common prefix detection to use the normalized datum. -- 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 →
-
Cosmetic fixes for radix sort
- ca9807dfec5b 19 (unreleased) landed
-
Skip common prefixes during radix sort
- f6bd9f0fe25a 19 (unreleased) landed
-
Perform radix sort on SortTuples with pass-by-value Datums
- ef3c3cf6d021 19 (unreleased) landed
-
Grab the low-hanging fruit from forcing sizeof(Datum) to 8.
- 6aebedc38497 19 (unreleased) cited
-
Add missing Datum conversions
- ff89e182d420 19 (unreleased) cited