Re: Removing a key from jsonb is sloooow

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Volkan Unsal <spocksplanet(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Removing a key from jsonb is sloooow
Date: 2019-07-17 15:09:29
Message-ID: 20053.1563376169@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Volkan Unsal <spocksplanet(at)gmail(dot)com> writes:
> I'm trying to remove a key from a jsonb column in a table with 10K rows,
> and the performance is abysmal. When the key is missing, it takes 5
> minutes. When the key is present, it takes even longer.

How wide are the jsonb values? It seems likely that most of this
is TOAST overhead [1], ie time to reassemble wide jsonb values
and then split them up again.

As Tumasgiu already mentioned, it'd likely be useful to suppress
updates of rows that don't actually need to change, assuming that
the key appears in a minority of rows. And an index could help
even more, by avoiding the need to reconstruct wide values to
see if the key appears in them.

Of course, if most of the rows need an update, neither of these
will help and you just gotta live with it. Possibly reconsider
your approach of using a large JSONB value to contain fields
you need to update individually. That's never going to be great
for performance. SQL (or at least Postgres) is incapable of
updating portions of columns efficiently.

regards, tom lane

[1] https://www.postgresql.org/docs/current/storage-toast.html

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Aaron Pelz 2019-07-17 15:53:58 Corrupt index stopping autovacuum system wide
Previous Message Adrian Klaver 2019-07-17 15:07:07 Re: Removing a key from jsonb is sloooow