From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | jian he <jian(dot)universality(at)gmail(dot)com>, pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: jsonb on-disk size calculation |
Date: | 2023-07-31 15:56:51 |
Message-ID: | 96442938-89cb-f0a3-882e-3f6272a1648a@aklaver.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 7/31/23 04:10, jian he 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.
I don't claim to understand all this but from jsonb.h
/*
* JsonbValue: In-memory representation of Jsonb. This is a convenient
* deserialized representation, that can easily support using the "val"
* union across underlying types during manipulation. The Jsonb on-disk
* representation has various alignment considerations.
*/
/*
* Key/value pair within an Object.
*
* This struct type is only used briefly while constructing a Jsonb; it is
* *not* the on-disk representation.
*
* Pairs with duplicate keys are de-duplicated. We store the originally
* observed pair ordering for the purpose of removing duplicates in a
* well-defined way (which is "last observed wins").
*/
>
>
>
>
>
--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | David Beck | 2023-07-31 23:18:35 | PORT 5432 ERROR |
Previous Message | Adrian Klaver | 2023-07-31 14:27:32 | Re: Completely Removing PostgreSQL |