| From: | Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com> |
|---|---|
| To: | Sehrope Sarkuni <sehrope(at)jackdb(dot)com> |
| Cc: | Pg Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: [PATCH] set_byte() with a count argument |
| Date: | 2026-09-22 09:55:14 |
| Message-ID: | CAEze2WgQCw_5OfSCviZo=+VZWP0jmd70zpZyjDA4qeZbvXu+dA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Mon, 21 Sept 2026 at 15:17, Sehrope Sarkuni <sehrope(at)jackdb(dot)com> wrote:
>
> On Mon, Sep 21, 2026 at 8:45 AM Matthias van de Meent
> <boekewurm+postgres(at)gmail(dot)com> wrote:
> > On Mon, 21 Sept 2026 at 14:23, Sehrope Sarkuni <sehrope(at)jackdb(dot)com> wrote:
> > > Today this needs nested set_byte() calls, each copying the whole
> > > value. The new form does one copy and one memset().
> >
> > Doesn't the `overlay(bytea, ...)` function already provide the feature
> > you're looking for (possibly combined with repeat() for ease of use)?
> > See https://www.postgresql.org/docs/current/functions-binarystring.html#id-1.5.8.11.5.2.2.6.1.1.1
> > and/or the ISO SQL spec for its specification.
>
> Yes, it's possible, but seems clunky and has the extra intermediate
> alloc for the repeat and decode:
Right, but implementing a repeat() for bytea should remove the alloc
and memory scan of decode(), and (IMO) would be a more universally
useful addition.
Do you have a workload in mind that would hit this operation hard
enough that the additional allocs (and function calls) becomes a
significant overhead, or other reasons why overlay's behaviour is
impractical for your workload?
Note, I'm not a huge fan of a 'count' argument in set_byte, as the
function name implies a singular byte being set.
Kind regards,
Matthias van de Meent
Databricks (https://www.databricks.com)
PS, for the reader: Even if it avoids the cost of decode() by using a
direct text-to-bytea binary cast, repeat('\xXX', N)::bytea is not a
good enough solution because that rejects NUL bytes, and won't produce
byteas that are not valid as text (i.e. ones filled with only hex
values 0x80-0xFF).
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Amit Kapila | 2026-09-22 10:03:01 | Re: Logical replication can lose an update after concurrent index invalidation |
| Previous Message | Florin Irion | 2026-09-22 09:46:10 | Re: Proposal: Supporting URI SAN in Certificate Authentication |