From: Tom Lane <tgl@sss.pgh.pa.us>
To: Volkan Unsal <spocksplanet@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Removing a key from jsonb is sloooow
Date: Wed, 17 Jul 2019 11:09:29 -0400
Message-ID: <20053.1563376169@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMcqKmnaJS_xnuKY6j2e+uZbHXhrtDx6SaDcRp-ZMYPfAbsOKw@mail.gmail.com>
References: <CAMcqKmnaJS_xnuKY6j2e+uZbHXhrtDx6SaDcRp-ZMYPfAbsOKw@mail.gmail.com>
Volkan Unsal <spocksplanet@gmail.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, spocksplanet@gmail.com
Subject: Re: Removing a key from jsonb is sloooow
In-Reply-To: <20053.1563376169@sss.pgh.pa.us>
References: <CAMcqKmnaJS_xnuKY6j2e+uZbHXhrtDx6SaDcRp-ZMYPfAbsOKw@mail.gmail.com> <20053.1563376169@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox