From: Dmitry Dolgov <9erthalion6@gmail.com>
To: Mitar <mmitar@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Why is writing JSONB faster than just JSON?
Date: Wed, 14 Apr 2021 10:48:45 +0200
Message-ID: <20210414084845.rkbe525twb4jr4fw@localhost> (raw)
In-Reply-To: <CAKLmikORKREgCE8F69NUcbi6aSo-ZrU75P0Jb8adaqpEVqS0Kg@mail.gmail.com>
References: <CAKLmikORKREgCE8F69NUcbi6aSo-ZrU75P0Jb8adaqpEVqS0Kg@mail.gmail.com>
> On Tue, Apr 13, 2021 at 11:38:04PM -0700, Mitar wrote:
> Hi!
>
> I have a project where we among other data want to store static JSON
> objects which can get pretty large (10-100 KB). I was trying to
> evaluate how it would work if we simply store it as an additional
> column in a PostgreSQL database. So I made a benchmark [1]. The
> results surprised me a bit and I am writing here because I would like
> to understand them. Namely, it looks like writing into a jsonb typed
> column is 30% faster than writing into a json typed column. Why is
> that? Does not jsonb require parsing of JSON and conversion? That
> should be slower than just storing a blob as-is?
>
> [1] https://gitlab.com/mitar/benchmark-pg-json
Interesting. I've tried to reproduce the schema and queries from the repository
above (with a different generated data though and without the app itself) and
indeed got a bit slower (not 30%, but visibly) execution for json column
instead of jsonb. There are couple of important points:
* Parsing is happening in both cases, for json it's done for validation
purposes.
* Compression of json data is actually dominates the runtime load for large
json objects, making other factors less visible and reducing difference in
size (jsonb also should be a bit bigger, that's why I would think it would be
slower).
* At the same time perf shows that json compression spends a bit more time in
pglz_find_match (mostly around accessing and checking history entries), which
is compression optimization via history table. So probably due to differences
in data layout this optimization works slightly worse for plain json than for
jsonb?
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: 9erthalion6@gmail.com, mmitar@gmail.com
Subject: Re: Why is writing JSONB faster than just JSON?
In-Reply-To: <20210414084845.rkbe525twb4jr4fw@localhost>
References: <CAKLmikORKREgCE8F69NUcbi6aSo-ZrU75P0Jb8adaqpEVqS0Kg@mail.gmail.com> <20210414084845.rkbe525twb4jr4fw@localhost>
* 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