Re: tuple radix sort
David Geier <geidav.pg@gmail.com>
From: David Geier <geidav.pg@gmail.com>
To: John Naylor <johncnaylorls@gmail.com>,
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Peter Geoghegan <pg@bowt.ie>
Date: 2025-11-12T14:28:37Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Skip common prefixes during radix sort
- f6bd9f0fe25a 19 (unreleased) landed
-
Perform radix sort on SortTuples with pass-by-value Datums
- ef3c3cf6d021 19 (unreleased) landed
On 29.10.2025 07:28, John Naylor wrote: > > Next steps: Try to find regressions (help welcome here). The v1 patch > has some optimizations, but in other ways things are simple and/or > wasteful. Exactly how things fit together will be informed by what, if > anything, has to be done to avoid regressions. I suspect the challenge > will be multikey sorts when the first key has low cardinality. This is > because tiebreaks are necessarily postponed rather than taken care of > up front. I'm optimistic, since low cardinality cases can be even > faster than our B&M qsort, so we have some headroom: Hi John, I've also been looking into radix sort the last days to accelerate GIN index builds. Ordering and removing duplicates requires a fast sort in generate_trgm(). My own implementation (likely slower than the algorithms you used) also showed a decent speedup. Beyond that there are many more places in the code base that could be changed to use radix sort instead of qsort. What would be great is if we could build a generic radix sort implementation, similarly to sort_template.h that can be used in other places. We would have to think a bit about the interface because instead of a comparator we would require some radix extraction callback. If you're open to that idea I could give abstracting the code a try. -- David Geier