From: | Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp> |
---|---|
To: | Aleksander Alekseev <aleksander(at)timescale(dot)com> |
Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Joel Jacobson <joel(at)compiler(dot)org>, David Fetter <david(at)fetter(dot)org> |
Subject: | Re: [PATCH] Add get_bytes() and set_bytes() functions |
Date: | 2024-08-16 10:32:24 |
Message-ID: | 20240816193224.e48dea50997ebffd609a0147@sraoss.co.jp |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, 16 Aug 2024 11:41:37 +0300
Aleksander Alekseev <aleksander(at)timescale(dot)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 <nagata(at)sraoss(dot)co(dot)jp>
From | Date | Subject | |
---|---|---|---|
Next Message | Dean Rasheed | 2024-08-16 10:39:46 | Re: Adding OLD/NEW support to RETURNING |
Previous Message | Heikki Linnakangas | 2024-08-16 10:28:57 | Re: Useless parameter 'cur_skey' in IndexScanOK |