Re: [PATCH] Avoid copying tuples that a bounded sort will discard

From: Alain LESAGE <alain(dot)lesage(at)dalibo(dot)com>
To: Chengpeng Yan <chengpeng_yan(at)outlook(dot)com>
Cc: John Naylor <johncnaylorls(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Greg Burd <greg(at)burd(dot)me>
Subject: Re: [PATCH] Avoid copying tuples that a bounded sort will discard
Date: 2026-12-03 19:07:58
Message-ID: 9f5d13fc-5d5f-4817-b77e-09e4add02516@dalibo.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Thu, Dec 3, 2026 Chengpeng Yan wrote:
> Most results are as expected, except "tuple, typical, wide" on x86. In
> some cases like this one, it seems related to hardware prefetching once
> the copy is gone; I'm still looking into it, and would welcome your view
> on whether such a hardware-dependent effect is acceptable.

I ran your setup.sql and bench.sh with master and v2 on three more
machines (Intel i5-1135G7, AMD Ryzen 7 5700G, Apple M1 Pro), on
cb94cb4124c with shared_buffers = 1GB. Median of 12 runs, ratio =
master / v2, with your two servers in the last columns:

i5 5700G M1 Pro Xeon ARM
Datum, typical, en_US.UTF-8 1.21 1.18 1.07 1.20 1.08
Datum, typical, "C" 1.33 1.24 1.39 1.21 1.46
Datum, worst, en_US.UTF-8 0.98 0.98 1.01 0.98 0.98
Datum, worst, "C" 0.93 0.93 0.95 0.89 1.00
tuple, typical, narrow 1.42 1.33 1.37 1.51 1.25
tuple, typical, wide 1.08 0.64 1.02 0.97 1.57
tuple, typical, projection 1.50 1.07 1.18 1.38 1.37
tuple, worst, narrow 0.90 0.84 0.94 0.90 1.03
tuple, worst, wide 0.88 0.89 0.88 0.95 0.90

The wide case is where the machines disagree most: from 0.64 on the
5700G to 1.57 on your ARM server. Across versions, on the same machines:

i5 5700G M1 Pro
v1 1.31 0.92 1.40
v1 w/o read_tuple_lines() 1.05 0.67 0.98
v2 1.08 0.64 1.02

So from v1 to v2, this case loses what read_tuple_lines() brought;
the other v2 changes make no difference here.

The worst cases are also slower than with v1, except the tuple ones on
the 5700G:

i5 5700G M1 Pro
v1 v2 v1 v2 v1 v2
Datum, worst, "C" 0.99 0.93 0.99 0.93 1.03 0.95
tuple, worst, narrow 0.99 0.90 0.86 0.84 0.99 0.94
tuple, worst, wide 0.98 0.88 0.88 0.89 0.94 0.88

Regards,
Alain

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2026-12-03 19:25:02 Re: Back-patch v19 improvements to common/int128.h?
Previous Message Masahiko Sawada 2026-12-03 18:44:27 Re: pg_dump writes a subscription's default slot name, which can't be restored