Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2022-06-27 Thread John Naylor
I wrote: > We can also shave a > few percent by having pg_utf8_verifystr use SSE2 for the ascii path. I > can look into this. Here's a patch for that. If the input is mostly ascii, I'd expect that part of the flame graph to shrink by 40-50% and give a small boost overall. -- John Naylor EDB:

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2022-06-24 Thread Andres Freund
Hi, On 2022-06-24 14:33:00 +0700, John Naylor wrote: > On Thu, Jun 23, 2022 at 9:06 PM Andres Freund wrote: > > It looks like there's quite a bit of low hanging fruits to optimize... > > Yeah, if escapes and control characters are rare, adding an SSE2 fast > path would give a boost to

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2022-06-24 Thread Jelte Fennema
> It's a decent amount of work to define one though... It's clearly not > acceptable to just dump out the internal representation, as already discussed > in this thread. I totally agree that it should be a well-defined format that doesn't leak stuff like endianness and alignment of the underlying

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2022-06-24 Thread John Naylor
On Thu, Jun 23, 2022 at 9:06 PM Andres Freund wrote: > It looks like there's quite a bit of low hanging fruits to optimize... Yeah, if escapes and control characters are rare, adding an SSE2 fast path would give a boost to json_lex_string: check 16 bytes at a time for those chars (plus the

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2022-06-23 Thread Andres Freund
Hi, On 2022-06-23 13:33:24 +0200, Jelte Fennema wrote: > (reviving an old thread) > > On Thu, 23 Jun 2022 at 13:29, Merlin Moncure wrote: > > I'll still stand other point I made though; I'd > > really want to see some benchmarks demonstrating benefit over > > competing approaches that work over

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2022-06-23 Thread Jelte Fennema
(attached is the flamegraph of the profile, in case others are interested) On Thu, 23 Jun 2022 at 13:33, Jelte Fennema wrote: > > (reviving an old thread) > > On Thu, 23 Jun 2022 at 13:29, Merlin Moncure wrote: > > I'll still stand other point I made though; I'd > > really want to see some

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2022-06-23 Thread Jelte Fennema
(reviving an old thread) On Thu, 23 Jun 2022 at 13:29, Merlin Moncure wrote: > I'll still stand other point I made though; I'd > really want to see some benchmarks demonstrating benefit over > competing approaches that work over the current formats. That should > frame the argument as to

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-03 Thread Merlin Moncure
On Fri, Nov 2, 2018 at 5:15 PM Andrew Dunstan wrote: > On 11/02/2018 05:20 PM, Andres Freund wrote: > > Hi, > > > > On 2018-11-02 17:02:24 -0400, Andrew Dunstan wrote: > >> On 11/02/2018 11:34 AM, Merlin Moncure wrote: > >>> Binary format consuming applications already have to deal with these >

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Andres Freund
On 2018-11-02 23:24:35 +0100, David Fetter wrote: > On Wed, Oct 31, 2018 at 11:18:46AM -0400, Stephen Frost wrote: > > Greetings, > > > > * Tom Lane (t...@sss.pgh.pa.us) wrote: > > > Stephen Frost writes: > > > > * Tom Lane (t...@sss.pgh.pa.us) wrote: > > > >> I dunno, I do not think it's a

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread David Fetter
On Wed, Oct 31, 2018 at 11:18:46AM -0400, Stephen Frost wrote: > Greetings, > > * Tom Lane (t...@sss.pgh.pa.us) wrote: > > Stephen Frost writes: > > > * Tom Lane (t...@sss.pgh.pa.us) wrote: > > >> I dunno, I do not think it's a great idea to expose jsonb's internal > > >> format to the world.

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Andrew Dunstan
On 11/02/2018 05:20 PM, Andres Freund wrote: Hi, On 2018-11-02 17:02:24 -0400, Andrew Dunstan wrote: On 11/02/2018 11:34 AM, Merlin Moncure wrote: Binary format consuming applications already have to deal with these kinds of issues. We already expose internal structures in the other

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Andres Freund
Hi, On 2018-11-02 17:02:24 -0400, Andrew Dunstan wrote: > On 11/02/2018 11:34 AM, Merlin Moncure wrote: > > > > Binary format consuming applications already have to deal with these > > kinds of issues. We already expose internal structures in the other > > functions -- not sure why jsonb is held

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Andres Freund
Hi, On 2018-11-02 11:52:59 -0400, Tom Lane wrote: > Andres' point about alignment is a pretty good one as well, if it applies > here --- I don't recall just what internal alignment requirements jsonb > has. We have not historically expected clients to have to deal with that. Certainly looks

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Andres Freund
On 2018-11-02 10:34:07 -0500, Merlin Moncure wrote: > On Wed, Oct 31, 2018 at 10:23 AM Andres Freund wrote: > > > > Hi, > > > > On 2018-10-31 11:13:13 -0400, Andrew Dunstan wrote: > > > I agree that just sending a blob of the internal format isn't a great > > > idea. > > > > It's entirely

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Andrew Dunstan
On 11/02/2018 11:34 AM, Merlin Moncure wrote: Binary format consuming applications already have to deal with these kinds of issues. We already expose internal structures in the other functions -- not sure why jsonb is held to a different standard. For other data types where format changes

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Merlin Moncure
On Fri, Nov 2, 2018 at 2:34 PM Stephen Frost wrote: > * Merlin Moncure (mmonc...@gmail.com) wrote: > As for what language it's written in- I don't think that matters much. > I'd very much expect it to be more performant to use binary if you're > working in C, of course, but there's no point

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Stephen Frost
Greetings, * Merlin Moncure (mmonc...@gmail.com) wrote: > On Fri, Nov 2, 2018 at 11:15 AM Stephen Frost wrote: > > * Merlin Moncure (mmonc...@gmail.com) wrote: > > > I'll still stand other point I made though; I'd > > > really want to see some benchmarks demonstrating benefit over > > >

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Merlin Moncure
On Fri, Nov 2, 2018 at 11:15 AM Stephen Frost wrote: > > Greetings, > > * Merlin Moncure (mmonc...@gmail.com) wrote: > > On Fri, Nov 2, 2018 at 10:53 AM Tom Lane wrote: > > > Andres' point about alignment is a pretty good one as well, if it applies > > > here --- I don't recall just what

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Stephen Frost
Greetings, * Merlin Moncure (mmonc...@gmail.com) wrote: > On Fri, Nov 2, 2018 at 10:53 AM Tom Lane wrote: > > Andres' point about alignment is a pretty good one as well, if it applies > > here --- I don't recall just what internal alignment requirements jsonb > > has. We have not historically

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Merlin Moncure
On Fri, Nov 2, 2018 at 10:53 AM Tom Lane wrote: > Merlin Moncure writes: > > On Wed, Oct 31, 2018 at 10:23 AM Andres Freund wrote: > >> It's entirely unacceptable afaict. Besides the whole "exposing > >> internals" issue, it's also at least not endianess safe, depends on the > >> local

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Tom Lane
Merlin Moncure writes: > On Wed, Oct 31, 2018 at 10:23 AM Andres Freund wrote: >> It's entirely unacceptable afaict. Besides the whole "exposing >> internals" issue, it's also at least not endianess safe, depends on the >> local alignment requirements (which differ both between platforms and >>

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Merlin Moncure
On Wed, Oct 31, 2018 at 10:23 AM Andres Freund wrote: > > Hi, > > On 2018-10-31 11:13:13 -0400, Andrew Dunstan wrote: > > I agree that just sending a blob of the internal format isn't a great idea. > > It's entirely unacceptable afaict. Besides the whole "exposing > internals" issue, it's also at

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Tomas Vondra
On 11/02/2018 01:42 PM, Daniel Gustafsson wrote: >> On 2 Nov 2018, at 04:21, Tom Lane wrote: > >> (In short, I remain unconvinced that we'd not be better off spending >> our effort on making json_out faster...) > > Shooting wildly from the hip, isn't this a case where we can > potentially

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Daniel Gustafsson
> On 2 Nov 2018, at 04:21, Tom Lane wrote: > (In short, I remain unconvinced that we'd not be better off spending > our effort on making json_out faster...) Shooting wildly from the hip, isn't this a case where we can potentially utilize the JIT infrastructure to speed it up? cheers ./daniel

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-02 Thread Stephen Frost
Greetings, * Tom Lane (t...@sss.pgh.pa.us) wrote: > Christian Ohler writes: > > On Wed, Oct 31, 2018 at 7:22 AM Tom Lane wrote: > >> If we're going to expose the > >> internal format, let's just change the definition of the type's binary > >> I/O format, thereby getting a win for purposes like

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-01 Thread Tom Lane
Christian Ohler writes: > On Wed, Oct 31, 2018 at 7:22 AM Tom Lane wrote: >> If we're going to expose the >> internal format, let's just change the definition of the type's binary >> I/O format, thereby getting a win for purposes like COPY BINARY as well. > How would this work from the driver's

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-11-01 Thread Christian Ohler
On Wed, Oct 31, 2018 at 7:22 AM Tom Lane wrote: > If we're going to expose the > internal format, let's just change the definition of the type's binary > I/O format, thereby getting a win for purposes like COPY BINARY as well. > We'd need to ensure that jsonb_recv could tell whether it was

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-10-31 Thread Andres Freund
Hi, On 2018-10-31 11:13:13 -0400, Andrew Dunstan wrote: > I agree that just sending a blob of the internal format isn't a great idea. It's entirely unacceptable afaict. Besides the whole "exposing internals" issue, it's also at least not endianess safe, depends on the local alignment

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-10-31 Thread Stephen Frost
Greetings, * Tom Lane (t...@sss.pgh.pa.us) wrote: > Stephen Frost writes: > > * Tom Lane (t...@sss.pgh.pa.us) wrote: > >> I dunno, I do not think it's a great idea to expose jsonb's internal > >> format to the world. We intentionally did not do that when the type > >> was first defined ---

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-10-31 Thread Andrew Dunstan
On 10/31/2018 10:21 AM, Tom Lane wrote: Stephen Frost writes: * Tom Lane (t...@sss.pgh.pa.us) wrote: I dunno, I do not think it's a great idea to expose jsonb's internal format to the world. We intentionally did not do that when the type was first defined --- that's why its binary I/O

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-10-31 Thread Tom Lane
Stephen Frost writes: > * Tom Lane (t...@sss.pgh.pa.us) wrote: >> I dunno, I do not think it's a great idea to expose jsonb's internal >> format to the world. We intentionally did not do that when the type >> was first defined --- that's why its binary I/O format isn't already >> like this ---

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-10-31 Thread Stephen Frost
Greetings, * Tom Lane (t...@sss.pgh.pa.us) wrote: > Kevin Van writes: > > This patch adds a new function that allows callers to receive binary jsonb. > > This change was proposed in the discussion here: > >

Re: WIP Patch: Add a function that returns binary JSONB as a bytea

2018-10-31 Thread Tom Lane
Kevin Van writes: > This patch adds a new function that allows callers to receive binary jsonb. > This change was proposed in the discussion here: > https://www.postgresql.org/message-id/CAOsiKEL7%2BKkV0C_hAJWxqwTg%2BPYVfiGPQ0yjFww7ECtqwBjb%2BQ%40mail.gmail.com > and the primary motivation is to

WIP Patch: Add a function that returns binary JSONB as a bytea

2018-10-31 Thread Kevin Van
This patch adds a new function that allows callers to receive binary jsonb. This change was proposed in the discussion here: https://www.postgresql.org/message-id/CAOsiKEL7%2BKkV0C_hAJWxqwTg%2BPYVfiGPQ0yjFww7ECtqwBjb%2BQ%40mail.gmail.com and the primary motivation is to reduce database load by