On Fri, 16 Aug 2024 11:41:37 +0300 Aleksander Alekseev <aleksan...@timescale.com> wrote:
> 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. Thank you for explanation. I understood the performance drawback. I supposed interfaces similar to lo_get, lo_put, loread, lowrite of large objects since they might be useful to access or modify a part of bytea like a binary file read by pg_read_binary_file. > > > 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. Should we fix the comment on byteaGetByte in passing, too? Regards, Yugo Nagata -- Yugo Nagata <nag...@sraoss.co.jp>