Re: jsonb on-disk size calculation

From: Junwang Zhao <zhjwpku(at)gmail(dot)com>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: jsonb on-disk size calculation
Date: 2023-08-01 03:58:35
Message-ID: CAEG8a3Kf7b2g8pz1jYJP08OC4jkC7sXGrLb5bX6XAPCLerd0dw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

convertJsonbObject convert JsonValue to Jsonb.

Jsonb->vl_len_ is 4 byte
JsonbContainer->header is 4 bytes
JsonbContainer->children is an array of two elements, that's 8 bytes
following the k/v part, 20 bytes

In total 36 bytes.

When Jsonb is stored to disk, I guess some conversion reduces the
vl_len_ to 1 byte, hence total 33 bytes,
but I cannot find the conversion logic.

On Mon, Jul 31, 2023 at 7:10 PM jian he <jian(dot)universality(at)gmail(dot)com> wrote:
>
>
> hi.
>
> drop table x;
> create table x(js jsonb);
> insert into x select '{"Hello world":1}'::jsonb;
> select pg_column_size(js) from x; -- return 33.
>
> based on src/include/utils/jsonb.h
> The key and value part is 20 bytes (is it correct?), Jsonb->vl_len_ is 4 byte, JsonbContainer->header is 4 bytes. That's 28 bytes.
>
> but now on-disk is 33 bytes.
> so I am not sure where the remaining bytes are.
>
>
>
>
>

--
Regards
Junwang Zhao

In response to

Browse pgsql-general by date

  From Date Subject
Next Message jacktby 2023-08-01 09:27:08 How to build a new grammer for pg?
Previous Message David Beck 2023-07-31 23:18:35 PORT 5432 ERROR