Re: [HACKERS] [PATCH] Generic type subscripting - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: [HACKERS] [PATCH] Generic type subscripting
Date
Msg-id CAFj8pRChx0q=xgMopKKgCkWGXAJO6Vw+Aqqh0NWVQWQE1HyNOg@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] [PATCH] Generic type subscripting  (Dmitry Dolgov <9erthalion6@gmail.com>)
Responses Re: [HACKERS] [PATCH] Generic type subscripting
List pgsql-hackers


čt 31. 12. 2020 v 15:27 odesílatel Dmitry Dolgov <9erthalion6@gmail.com> napsal:
> On Wed, Dec 30, 2020 at 09:01:37PM +0100, Dmitry Dolgov wrote:
> > make check fails
>
> Yeah, apparently I forgot to enable asserts back after the last
> benchmarking discussion, and missed some of those. Will fix.
>
> > 2. The index position was ignored.
> >
> > postgres=# update foo set a['a'][10] = '20';
> > UPDATE 1
> > postgres=# select * from foo;
> > ┌─────────────┐
> > │      a      │
> > ╞═════════════╡
> > │ {"a": [20]} │
> > └─────────────┘
> > (1 row)
>
> I just realized I haven't included "filling the gaps" part, that's why
> it works as before. Can add this too.
>
> > 1. quietly ignored update
> >
> > postgres=# update foo set a['a'][10] = '20';
> > UPDATE 1
> > postgres=# select * from foo;
> > ┌────┐
> > │ a  │
> > ╞════╡
> > │ {} │
> > └────┘
> > (1 row)
>
> This belongs to the original jsonb_set implementation. Although if we
> started to change it anyway with "filling the gaps", maybe it's fine to
> add one more flag to tune its behaviour in this case as well. I can
> check how complicated that could be.

Here is what I had in mind. Assert issue in main patch is fixed (nothing
serious, it was just the rawscalar check for an empty jsonb created
during assignment), and the second patch contains all the bits with
"filling the gaps" including your suggestion about creating the whole
path if it's not present. The latter (creating the chain of empty
objects) I haven't tested that much, but if there are any issues or
concerns I guess it will not prevent the main patch from going forward

the tests passed and filling gaps works well

but creating empty objects doesn't work

create table foo(a jsonb);

insert into foo values('{}');

postgres=# update foo set a['k'][1] = '20';
UPDATE 1
postgres=# select * from foo;
┌───────────────────┐
│         a         │
╞═══════════════════╡
│ {"k": [null, 20]} │
└───────────────────┘
(1 row)

it is ok

postgres=# update foo set a['k3'][10] = '20';
UPDATE 1
postgres=# select * from foo;
┌───────────────────┐
│         a         │
╞═══════════════════╡
│ {"k": [null, 20]} │
└───────────────────┘
(1 row)

the second update was not successful



.

pgsql-hackers by date:

Previous
From: Victor Yegorov
Date:
Subject: Re: Deleting older versions in unique indexes to avoid page splits
Next
From: Stephen Frost
Date:
Subject: Re: crash recovery vs partially written WAL