Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wUv9K-001XWf-0t for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Jun 2026 23:37:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wUv9J-003rrt-0c for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Jun 2026 23:37:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wUv9I-003rrl-2N for pgsql-hackers@lists.postgresql.org; Wed, 03 Jun 2026 23:37:24 +0000 Received: from mail-dy1-x1329.google.com ([2607:f8b0:4864:20::1329]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wUv9G-00000000z5o-3rBz for pgsql-hackers@lists.postgresql.org; Wed, 03 Jun 2026 23:37:23 +0000 Received: by mail-dy1-x1329.google.com with SMTP id 5a478bee46e88-30749947917so108439eec.1 for ; Wed, 03 Jun 2026 16:37:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780529842; cv=none; d=google.com; s=arc-20240605; b=fYB1ledDMMas4XbnSMB0WXa4nidNwkLmJB8HXr+GLDd7EaYymZ03mtdnTgCaFT6+l+ i0osYQEqfIXRqL2q8wNPjPilgFqkjXvXAf3jL1qnl7bmDMKOoJXb4pa4Dq1eCOQSrBt+ jK3tIux0ThLxaAp6kx5TUIETgjc1e+0PndWIC1OzDHd6qlzHxcGwkUTv2nzWMVQQ81aK b5QTELhFxpaJ0WknKnH+36u/ucTbJqh0kEss7cjpKrTWffk2abuyNykDQAb8e1DFuxeZ OHx8j3dTic7q9kW0S8EldOFKnPf/0M7MOI2+uk2Mbv5vDrx/i2vhUK3u7j7BMzk2MVCg XorA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:mime-version:dkim-signature; bh=GeoNXzzcp2imxOhHmhtonS7N4oC5vGz5BZZ6L7zhpCE=; fh=g0WqGWuQokdl1gje4fWca8nxWNo9Dqd/g9tQAGf/LI4=; b=Cm/AKWfcAat5iIyiG5iP3/rgLCqxeV667aomjdBY57oSKq5eMDNWN8dtziQ14YUabA oTNH6OCyTTCOFEHrEIKXDYABJDUrLMLtFNU/bimiCnA8ivy6MU3O+2dx4CocODth7emy pjx7L3ie3MVubVFy5e0rxmVx6E88RYVweGmqlLmKY8C6zivO5d9UscuEbvzfxm6/dcqd 8ZZn0pS3ZmFBesRB4INZVkoi96GHK1dXVJbelbuAA4rRPClxSLyh4FHPDxyLRqzNyLqk wuuwDqZRPn4eqNjPxI6RaGMqZF3fQc4f0Weq49GMwZ9FwxWCLJT0TMp8FPYPffJIkg6U exIw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780529842; x=1781134642; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=GeoNXzzcp2imxOhHmhtonS7N4oC5vGz5BZZ6L7zhpCE=; b=GXAoyPiz9ysG2CUM+K8rBxvJjNt3NnN0ltF7m1oPb960H1WycdF0gI5oXRWIyIH/t0 sOfDmege46bYo49EF9lhjJtEAnwvh0Ihs+3SIrp2Ncr+NGC88hmfvcknC4KCy3WH5RXR BPZDPMo8z8lAsxBfzpNA8iB4bHLszVtMX/yHYmrc3OuIH2JLPogfXyAFYhJC1qdgzG5z GYEWfwln8f7TEsPgr3mxXpSYIxhOD/FmTPnE/ygTWEguliK3YNc9sNF2tR6uZs2spIZt UmDTQWz/0RFXlnk2mhq1AL0lE9cZ0hQGdaIwyYKkTv/ViCuawVEKcTiPKq78UQYAhbvq lZVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780529842; x=1781134642; h=cc:to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GeoNXzzcp2imxOhHmhtonS7N4oC5vGz5BZZ6L7zhpCE=; b=YtYPy5F8se74BmHmYtR5wx/P7UCV+xi4T6PHtobeY85brXAqZ+EefoU+Vr310KJzz6 NzQ1GeNO9VAOVkGDzbFuCGJ2e5TC+eKnM0SFnTUzaZ35pvA+RFUtrgtn0HrJUiGZ5Nqu P8s+VGRY/OS/XpBCUzxGSHJBnitgDXgAtMDmdBRNgm3NJEa0ZfY5klO01+FB1wkWW9yp d/GJdiOWYX3YUEMkCkF/ac92G8w+xDrpc8rlfZDOonVOXsGJiHRKra05TUhmWMR5RQVs XYKAawjuKXmNqhZx/ziubzh/qbJlF50kApH5r4I/8VsBqYksKvdq4Uy6l4AAG9CEmEji zDjg== X-Gm-Message-State: AOJu0YyIzhn9K0O0RoqegmPk8kwka5ciyD7DrF55AsDhvd9EUImtS9Bj ikiuK5rf9hhsk6T2gb/dYyfHY88+HY6ma9/331TJ/I6sP1oK5AeelZyofwJiuEwMU1HLJTCYkqZ DxJd9nCDwq2YMemp4BlPk4L9MManVe7QvwtFoVnI= X-Gm-Gg: Acq92OG35f+1YPP5uFptmtcTeklHCkrL68RkJrP0QVmTXpqRg7J5tkVuiAZCQQbVUdB I6hBwJPaSUi+g3snP/LsxD8TdwQ1QE7RsfxhzWGRyLk+HDWEUPR8mYXwG1fiW3t7DHVvi5YTNK2 Ysljicov4RqRHRqseex60x6eC4hudw424Ux5Ix75aXH+5Eo1WErBBmvWwJbgnk8tmDOhw8ZobMg GCiaohDdkGQvkrxDXYjPG5dQCM9S6MUk9UexB2Qv2Nd2AWuh9Sa7ONda/orpdSkulwGR8fAZgct VDQ1h4Ny3KmXypCENH5QGmSRuG1mHeecZKpi1LdH9XDn/K7/PF2g X-Received: by 2002:a05:7300:ec01:b0:304:c651:bdfe with SMTP id 5a478bee46e88-3074fbbc0cbmr2944816eec.17.1780529841581; Wed, 03 Jun 2026 16:37:21 -0700 (PDT) MIME-Version: 1.0 From: Baji Shaik Date: Wed, 3 Jun 2026 18:37:09 -0500 X-Gm-Features: AVHnY4IufM4gtDPNLMXu0_SHkBcWfOS-V5M2apCjJy46bNclUEp-e2-ODk2hOP4 Message-ID: Subject: [PATCH] Use ssup_datum_*_cmp for int2, oid, and oid8 sort support To: pgsql-hackers@lists.postgresql.org Cc: john.naylor@postgresql.org, michael@paquier.xyz Content-Type: multipart/mixed; boundary="000000000000b8ace6065361e89f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b8ace6065361e89f Content-Type: multipart/alternative; boundary="000000000000b8ace5065361e89d" --000000000000b8ace5065361e89d Content-Type: text/plain; charset="UTF-8" Hi, While auditing nbtcompare.c, I noticed that int2, oid, and oid8 sortsupport functions use custom local fastcmp helpers that are functionally equivalent to the existing ssup_datum_int32_cmp (for int2) and ssup_datum_unsigned_cmp (for oid, oid8). This prevents these types from hitting the radix sort fast path added in commit ef3c3cf6d02 [1], which dispatches based on the comparator function pointer. The original 2021-2022 thread that introduced the ssup_datum_*_cmp helpers (commit 6974924347c, Apr 2022) [2] covered int4, int8, timestamp, date, and the abbreviated-key types (text, uuid, macaddr, inet, bytea). int2 and oid weren't called out in that discussion, and oid8 didn't exist at the time, it was added in Jan 2026 [3] and inherited the custom fastcmp pattern from oid, about a month before radix sort landed. This patch fills those gaps. Switching to the existing helpers makes these types eligible for radix sort. Benchmark (10M-row single-key sort): Type Before After Speedup ---- ------ ----- ------- int2 2440 ms 1778 ms ~27% oid 2875 ms 2073 ms ~28% oid8 2837 ms 2042 ms ~28% int4 -- 1765 ms (baseline) int8 -- 2031 ms (baseline) The patch just replaces the comparator assignment and removes the now-unused local fastcmp functions. No behavioral change and the helpers produce identical results. int2 uses ssup_datum_int32_cmp because there is no int16-specific helper, every int16 fits losslessly in int32, and int32_cmp is more efficient than signed_cmp (4-byte radix passes instead of 8). Other custom fastcmp users in core (float4/float8, varlena types) cannot be trivially switched due to NaN handling or locale-dependent comparison, so they are left as-is. Tested with make check (245/245 pass) and make isolation/check (128/128 pass). [1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=ef3c3cf6d02 [2] https://www.postgresql.org/message-id/flat/CA%2BhUKGJ2-eaDqAum5bxhpMNhvuJmRDZxB_Tow0n-gse%2BHG0Yig%40mail.gmail.com [3] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=b139bd3b6 Thanks, Baji Shaik --000000000000b8ace5065361e89d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

While auditing nbtcompare.c, I noticed that int= 2, oid, and oid8
sortsupport functions use custom local fastcmp helpers = that are
functionally equivalent to the existing ssup_datum_int32_cmp (f= or
int2) and ssup_datum_unsigned_cmp (for oid, oid8).

This preven= ts these types from hitting the radix sort fast path
added in commit ef3= c3cf6d02 [1], which dispatches based on the
comparator function pointer.=

The original 2021-2022 thread that introduced the ssup_datum_*_cmp<= br>helpers (commit 6974924347c, Apr 2022) [2] covered int4, int8,
timest= amp, date, and the abbreviated-key types (text, uuid, macaddr,
inet, byt= ea). =C2=A0int2 and oid weren't called out in that discussion,
and o= id8 didn't exist at the time, it was added in Jan 2026 [3]
and inher= ited the custom fastcmp pattern from oid, about a month
before radix sor= t landed.=C2=A0 This patch fills those gaps.

Switching to the existi= ng helpers makes these types eligible for
radix sort.=C2=A0 Benchmark (1= 0M-row single-key sort):

=C2=A0 Type =C2=A0 =C2=A0 Before =C2=A0 =C2= =A0After =C2=A0 =C2=A0 Speedup
=C2=A0 ---- =C2=A0 =C2=A0 ------ =C2=A0 = =C2=A0----- =C2=A0 =C2=A0 -------
=C2=A0 int2 =C2=A0 =C2=A0 2440 ms =C2= =A0 1778 ms =C2=A0 ~27%
=C2=A0 oid =C2=A0 =C2=A0 =C2=A02875 ms =C2=A0 20= 73 ms =C2=A0 ~28%
=C2=A0 oid8 =C2=A0 =C2=A0 2837 ms =C2=A0 2042 ms =C2= =A0 ~28%
=C2=A0 int4 =C2=A0 =C2=A0 -- =C2=A0 =C2=A0 =C2=A0 =C2=A01765 ms= =C2=A0 (baseline)
=C2=A0 int8 =C2=A0 =C2=A0 -- =C2=A0 =C2=A0 =C2=A0 =C2= =A02031 ms =C2=A0 (baseline)

The patch just replaces the comparator = assignment and removes the
now-unused local fastcmp functions.=C2=A0 No = behavioral change and the
helpers produce identical results.

int2= uses ssup_datum_int32_cmp because there is no int16-specific
helper, ev= ery int16 fits losslessly in int32, and int32_cmp is more
efficient than= signed_cmp (4-byte radix passes instead of 8).

Other custom fastcmp= users in core (float4/float8, varlena types)
cannot be trivially switch= ed due to NaN handling or locale-dependent
comparison, so they are left = as-is.

Tested with make check (245/245 pass) and make isolation/chec= k
(128/128 pass).

[1] https://git.postgresql.or= g/gitweb/?p=3Dpostgresql.git;a=3Dcommit;h=3Def3c3cf6d02
[2] https://www.postgresql.org/me= ssage-id/flat/CA%2BhUKGJ2-eaDqAum5bxhpMNhvuJmRDZxB_Tow0n-gse%2BHG0Yig%40mai= l.gmail.com
[3] https://git.postgresql.org/gitweb/?p= =3Dpostgresql.git;a=3Dcommit;h=3Db139bd3b6

Thank= s,
Baji Shaik
--000000000000b8ace5065361e89d-- --000000000000b8ace6065361e89f Content-Type: application/octet-stream; name="0001-Use-ssup_datum_-_cmp-for-int2-oid-and-oid8-sort-supp.patch" Content-Disposition: attachment; filename="0001-Use-ssup_datum_-_cmp-for-int2-oid-and-oid8-sort-supp.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_mpyopil30 RnJvbSBlMjNmYzFjOWEyODQzNWY1NmNiYjI0ZTZmYzIzYzg1ZGRl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