public inbox for [email protected]
help / color / mirror / Atom feedFrom: Merlin Moncure <[email protected]>
To: David G. Johnston <[email protected]>
Cc: Adrian Klaver <[email protected]>
Cc: veem v <[email protected]>
Cc: pgsql-general <[email protected]>
Subject: Re: Performance of JSON type in postgres
Date: Tue, 15 Jul 2025 11:32:42 -0600
Message-ID: <CAHyXU0xQGXFBZ10GtqTkXL3_b8FbB79qP+XS2XCfxp+6WuH1Cg@mail.gmail.com> (raw)
In-Reply-To: <CAKFQuwarbmz7=yg14h6u-UhGPfbT56TsX8S6w9wVdMHGiWxbYg@mail.gmail.com>
References: <CAB+=1TU2bi8UkdD94kMizsTrTBUgqbdWKtM4Lq67+BMi6Vt1qA@mail.gmail.com>
<[email protected]>
<CAKFQuwarbmz7=yg14h6u-UhGPfbT56TsX8S6w9wVdMHGiWxbYg@mail.gmail.com>
On Mon, Jul 14, 2025 at 2:01 PM David G. Johnston <
[email protected]> wrote:
> On Mon, Jul 14, 2025 at 12:54 PM Adrian Klaver <[email protected]>
> wrote:
>
>> On 7/14/25 12:51, veem v wrote:
>> > So I want to
>> > understand the experts' opinion on this which I believe will be
>> > crucial during design itself.
>>
>> It is spelled out here:
>>
>> https://www.postgresql.org/docs/current/datatype-json.html
>>
>>
> I've taken to heart the main takeaway from that page:
>
> "In general, most applications should prefer to store JSON data as jsonb,
> unless there are quite specialized needs, such as legacy assumptions about
> ordering of object keys."
>
I don't think the documentation is accurate at all, unless one of those
specialized needs is to 'be faster'. json serialization is more than 2x
faster based on simple testing (see below). This is absolutely not a
trivial difference.
I would say, use json for serialization, use jsonb for data storage, unless
the precise structure of the input document is important.
merlin
leaselock_iam@leaselock_prod=> explain analyze select json_agg(l) from (
select l from llcore.lease l limit 10000) q;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=405.52..405.53 rows=1 width=32) (actual
time=69.043..69.048 rows=1 loops=1)
-> Limit (cost=0.00..380.52 rows=10000 width=247) (actual
time=0.017..9.764 rows=10000 loops=1)
-> Seq Scan on lease l (cost=0.00..100383.89 rows=2638089
width=247) (actual time=0.016..8.831 rows=10000 loops=1)
Planning Time: 0.109 ms
Execution Time: 69.088 ms
(5 rows)
Time: 160.560 ms
leaselock_iam@leaselock_prod=> explain analyze select jsonb_agg(l) from (
select l from llcore.lease l limit 10000) q;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
Aggregate (cost=405.52..405.53 rows=1 width=32) (actual
time=146.139..146.141 rows=1 loops=1)
-> Limit (cost=0.00..380.52 rows=10000 width=247) (actual
time=0.017..20.837 rows=10000 loops=1)
-> Seq Scan on lease l (cost=0.00..100383.89 rows=2638089
width=247) (actual time=0.016..19.975 rows=10000 loops=1)
Planning Time: 0.108 ms
Execution Time: 152.277 ms
view thread (2+ messages) latest in thread
reply
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 using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: Performance of JSON type in postgres
In-Reply-To: <CAHyXU0xQGXFBZ10GtqTkXL3_b8FbB79qP+XS2XCfxp+6WuH1Cg@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox