Re: [PATCH] Add get_bytes() and set_bytes() functions
Aleksander Alekseev <aleksander@timescale.com>
From: Aleksander Alekseev <aleksander@timescale.com>
To: pgsql-hackers@lists.postgresql.org
Cc: Yugo Nagata <nagata@sraoss.co.jp>,
Dean Rasheed <dean.a.rasheed@gmail.com>, Joel Jacobson <joel@compiler.org>, David Fetter <david@fetter.org>
Date: 2024-08-16T08:41:37Z
Lists: pgsql-hackers
Attachments
- v2-0001-Add-get_bytes-and-set_bytes-functions.patch (application/octet-stream) patch v2-0001
Hi,
> When we add such casts between bytea and the integer/numeric types,
> one of the problems mentioned the first of the thread, that is,
> "we don't have a convenient way of casting a bytea to an integer / bigint
> and vice versa", would seem be resolved.
>
> On the other hand, I suppose get_bytes() and set_bytes() are still useful
> for extracting bytes from byteas, etc. If casting is no longer the main
> purpose of these functions, are variations that get_bytes returns bytea
> instead of bigint, and set_bytes receives bytea as the newvalue argument
> useful? I wonder it would eliminate the restrict that size cannot be larger
> than 8.
No, casting between bytea and numeric will not replace get_bytes() /
set_bytes() for performance reasons.
Consider the case when you want to extract an int4 from a bytea.
get_bytes() is going to be very fast while substr() -> ::numeric ->
::integer chain will require unnecessary copying and conversions.
Casting between bytea and numeric is only useful when one has to deal
with integers larger than 8 bytes. Whether this happens often is a
debatable question.
> Here are my very trivial comments on the patch.
>
> + * this routine treats "bytea" as an array of bytes.
>
> Maybe, the sentence should start with "This ... ".
>
> + while(size)
> + {
>
> I wonder inserting a space after "while" is the standard style.
Thanks, fixed.
--
Best regards,
Aleksander Alekseev
Commits
-
Allow casting between bytea and integer types.
- 6da469badaff 18.0 landed