Re: Speed up lpad() and rpad() for one-byte padding strings

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Sehrope Sarkuni <sehrope(at)jackdb(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Speed up lpad() and rpad() for one-byte padding strings
Date: 2026-09-23 14:41:36
Message-ID: arPlICNzFXv6zTbS@nathan
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Sep 23, 2026 at 10:10:09AM -0400, Sehrope Sarkuni wrote:
> lpad() and rpad() pad one character at a time, calling
> pg_mblen_range() and memcpy() once per padding char. When the padding
> string is a single byte, e.g., lpad(x, n, '0') or rpad(x, n, ' '),
> the padding is that byte repeated, so the attached patch fills it with
> one memset().

I wonder if we could expand these gains by using SIMD whenever the vector
length is divisible by the padding string length. My hunch is that's where
a lot of the memset() gains come from.

--
nathan

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jonathan S. Katz 2026-09-23 14:51:31 Re: add list of major features to the v19 release notes
Previous Message Tom Lane 2026-09-23 14:35:49 Re: run pgindent in CI