public inbox for [email protected]  
help / color / mirror / Atom feed
Data Type Size Calculation
4+ messages / 4 participants
[nested] [flat]

* Data Type Size Calculation
@ 2022-02-11 20:12 PG Doc comments form <[email protected]>
  2022-02-14 18:51 ` Re: Data Type Size Calculation Bruce Momjian <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: PG Doc comments form @ 2022-02-11 20:12 UTC (permalink / raw)
  To: [email protected]; +Cc: [email protected]

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/13/datatype-numeric.html
Description:

> The actual storage requirement is two bytes for each group of four decimal
digits, plus three to eight bytes overhead.

Please describe what 'overhead' means. 

I'd like to be able to calculate the data size of NUMBER(19,4). I can
calculate 2 bytes per 4 digits... with 19 digits, I have 5 groups of 4
digits, 

so the data length I seek is 5 bytes + overhead... then I'm left hanging.
:(

Troy.
#


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Data Type Size Calculation
  2022-02-11 20:12 Data Type Size Calculation PG Doc comments form <[email protected]>
@ 2022-02-14 18:51 ` Bruce Momjian <[email protected]>
  2022-02-15 18:50   ` Re: Data Type Size Calculation Troy Frericks <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Bruce Momjian @ 2022-02-14 18:51 UTC (permalink / raw)
  To: [email protected]; [email protected]

On Fri, Feb 11, 2022 at 08:12:08PM +0000, PG Doc comments form wrote:
> The following documentation comment has been logged on the website:
> 
> Page: https://www.postgresql.org/docs/13/datatype-numeric.html
> Description:
> 
> > The actual storage requirement is two bytes for each group of four decimal
> digits, plus three to eight bytes overhead.
> 
> Please describe what 'overhead' means. 
> 
> I'd like to be able to calculate the data size of NUMBER(19,4). I can
> calculate 2 bytes per 4 digits... with 19 digits, I have 5 groups of 4
> digits, 
> 
> so the data length I seek is 5 bytes + overhead... then I'm left hanging.
> :(

Well, you can create it and then call pg_column_size():

	CREATE TABLE test (x NUMERIC(19,4));
	
	SELECT pg_column_size('test.x');
	 pg_column_size
	----------------
	              7

If you want more details, you will need to look at the source code.

-- 
  Bruce Momjian  <[email protected]>        https://momjian.us
  EDB                                      https://enterprisedb.com

  If only the physical world exists, free will is an illusion.






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Data Type Size Calculation
  2022-02-11 20:12 Data Type Size Calculation PG Doc comments form <[email protected]>
  2022-02-14 18:51 ` Re: Data Type Size Calculation Bruce Momjian <[email protected]>
@ 2022-02-15 18:50   ` Troy Frericks <[email protected]>
  2022-02-16 04:24     ` Re: Data Type Size Calculation Jian He <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Troy Frericks @ 2022-02-15 18:50 UTC (permalink / raw)
  To: Bruce Momjian <[email protected]>; +Cc: [email protected]; [email protected]

For now, yes... I'm suggesting that the documentation be completed by
adding a few sentences few extra sentences.
Troy.
#


On Mon, Feb 14, 2022, 12:51 Bruce Momjian <[email protected]> wrote:

> On Fri, Feb 11, 2022 at 08:12:08PM +0000, PG Doc comments form wrote:
> > The following documentation comment has been logged on the website:
> >
> > Page: https://www.postgresql.org/docs/13/datatype-numeric.html
> > Description:
> >
> > > The actual storage requirement is two bytes for each group of four
> decimal
> > digits, plus three to eight bytes overhead.
> >
> > Please describe what 'overhead' means.
> >
> > I'd like to be able to calculate the data size of NUMBER(19,4). I can
> > calculate 2 bytes per 4 digits... with 19 digits, I have 5 groups of 4
> > digits,
> >
> > so the data length I seek is 5 bytes + overhead... then I'm left hanging.
> > :(
>
> Well, you can create it and then call pg_column_size():
>
>         CREATE TABLE test (x NUMERIC(19,4));
>
>         SELECT pg_column_size('test.x');
>          pg_column_size
>         ----------------
>                       7
>
> If you want more details, you will need to look at the source code.
>
> --
>   Bruce Momjian  <[email protected]>        https://momjian.us
>   EDB                                      https://enterprisedb.com
>
>   If only the physical world exists, free will is an illusion.
>
>


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Data Type Size Calculation
  2022-02-11 20:12 Data Type Size Calculation PG Doc comments form <[email protected]>
  2022-02-14 18:51 ` Re: Data Type Size Calculation Bruce Momjian <[email protected]>
  2022-02-15 18:50   ` Re: Data Type Size Calculation Troy Frericks <[email protected]>
@ 2022-02-16 04:24     ` Jian He <[email protected]>
  0 siblings, 0 replies; 4+ messages in thread

From: Jian He @ 2022-02-16 04:24 UTC (permalink / raw)
  To: Troy Frericks <[email protected]>; +Cc: Bruce Momjian <[email protected]>; [email protected]; [email protected]

https://www.depesz.com/2022/02/13/how-much-disk-space-you-can-save-by-using-int4-int-instead-of-int8...

Hope this link is useful.


 create table testb as select 'true'::bool as b from
generate_series(1,1000000) i;SELECT 1000000

$ \dt+ testb
                                  List of relations
 Schema │ Name  │ Type  │ Owner  │ Persistence │ Access method │ Size
│ Description
────────┼───────┼───────┼────────┼─────────────┼───────────────┼───────┼─────────────
 public │ testb │ table │ depesz │ permanent   │ heap          │ 35 MB │


Why is that, though? From what I gather the answer is: performance. I don't
> know low-level details, but based on what I understand, processors process
> data in arch-dependent block sizes. 64bit processor works on 64 bits. And
> this means that if you want to do something on int4 value, that is part of
> 8 byte block, you have to add operation to zero the other 32 bits.
>

On Wed, Feb 16, 2022 at 12:26 AM Troy Frericks <[email protected]>
wrote:

> For now, yes... I'm suggesting that the documentation be completed by
> adding a few sentences few extra sentences.
> Troy.
> #
>
>
> On Mon, Feb 14, 2022, 12:51 Bruce Momjian <[email protected]> wrote:
>
>> On Fri, Feb 11, 2022 at 08:12:08PM +0000, PG Doc comments form wrote:
>> > The following documentation comment has been logged on the website:
>> >
>> > Page: https://www.postgresql.org/docs/13/datatype-numeric.html
>> > Description:
>> >
>> > > The actual storage requirement is two bytes for each group of four
>> decimal
>> > digits, plus three to eight bytes overhead.
>> >
>> > Please describe what 'overhead' means.
>> >
>> > I'd like to be able to calculate the data size of NUMBER(19,4). I can
>> > calculate 2 bytes per 4 digits... with 19 digits, I have 5 groups of 4
>> > digits,
>> >
>> > so the data length I seek is 5 bytes + overhead... then I'm left
>> hanging.
>> > :(
>>
>> Well, you can create it and then call pg_column_size():
>>
>>         CREATE TABLE test (x NUMERIC(19,4));
>>
>>         SELECT pg_column_size('test.x');
>>          pg_column_size
>>         ----------------
>>                       7
>>
>> If you want more details, you will need to look at the source code.
>>
>> --
>>   Bruce Momjian  <[email protected]>        https://momjian.us
>>   EDB                                      https://enterprisedb.com
>>
>>   If only the physical world exists, free will is an illusion.
>>
>>


^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2022-02-16 04:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-02-11 20:12 Data Type Size Calculation PG Doc comments form <[email protected]>
2022-02-14 18:51 ` Bruce Momjian <[email protected]>
2022-02-15 18:50   ` Troy Frericks <[email protected]>
2022-02-16 04:24     ` Jian He <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox