Re: Small improvements to substring() - Mailing list pgsql-hackers

From Junwang Zhao
Subject Re: Small improvements to substring()
Date
Msg-id CAEG8a3Ko+OCW6-stTKjmcwBAcn2qdFez9XPua2h41dAudf5w7Q@mail.gmail.com
Whole thread Raw
In response to Small improvements to substring()  (Thomas Munro <thomas.munro@gmail.com>)
List pgsql-hackers
Hi Thomas,

On Sun, Feb 15, 2026 at 5:41 AM Thomas Munro <thomas.munro@gmail.com> wrote:
>
> Hi,
>
> As recently discussed on pgsql-bugs[1], substring() does unnecessary
> work that can easily be deleted.  Here's a patch to try that.
>
> [1] https://www.postgresql.org/message-id/flat/19406-9867fddddd724fca%40postgresql.org

A simple benchmark indicates an approximately 20% performance improvement.
I have not identified any corner cases where the patch would introduce
regressions, so +1.

I test it on an old intel chip mac, test query used:

EXPLAIN ANALYZE
SELECT substring(repeat('中', i * 2), 1, i)
FROM generate_series(1, 10000) AS i;

--
Regards
Junwang Zhao



pgsql-hackers by date:

Previous
From: John Naylor
Date:
Subject: centralize CPU feature detection
Next
From: Mihail Nikalayeu
Date:
Subject: Re: Adding REPACK [concurrently]