pgsql: Skip common prefixes during radix sort

From: John Naylor <john(dot)naylor(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Skip common prefixes during radix sort
Date: 2026-04-01 07:19:16
Message-ID: E1w7pr9-002QQU-2J@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Skip common prefixes during radix sort

During the counting step, keep track of the bits that are the same
for the entire input. If we counted only a single distinct byte,
the next recursion will start at the next byte position that has
more than one distinct byte in the input. This allows us to skip over
multiple passes where the byte is the same for the entire input.

This provides a significant speedup for integers that have some upper
bytes with all-zeros or all-ones, which is common.

Reviewed-by: Chengpeng Yan <chengpeng_yan(at)outlook(dot)com>
Reviewed-by: ChangAo Chen <cca5507(at)qq(dot)com>
Discussion: https://postgr.es/m/CANWCAZYpGMDSSwAa18fOxJGXaPzVdyPsWpOkfCX32DWh3Qznzw@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f6bd9f0fe25a3cea06e26204cc75cc6e954c4577

Modified Files
--------------
src/backend/utils/sort/tuplesort.c | 44 ++++++++++++++++++++++++++++++++++----
1 file changed, 40 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Christoph Berg 2026-04-01 08:20:12 Re: pgsql: test_aio: Add basic tests for StartReadBuffers()
Previous Message Fujii Masao 2026-04-01 06:44:04 pgsql: Reduce log level of some logical decoding messages from LOG to D