Re: storage size of "bit" data type..

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: "Decibel!" <decibel(at)decibel(dot)org>
Cc: Michael Glaesemann <grzm(at)seespotcode(dot)net>, Alex Mayrhofer <axelm(at)nona(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: storage size of "bit" data type..
Date: 2008-03-17 23:49:40
Message-ID: 200803172349.m2HNnee29872@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Added to TODO:

* Reduce BIT data type overhead using short varlena headers

http://archives.postgresql.org/pgsql-general/2007-12/msg00273.php

---------------------------------------------------------------------------

Decibel! wrote:
> On Dec 5, 2007, at 7:23 PM, Michael Glaesemann wrote:
> > On Dec 5, 2007, at 14:19 , Alex Mayrhofer wrote:
> >> i'm trying to find out the storage size for bit(n) data. My
> >> initial assumption would be that for any 8 bits, one byte of
> >> storage is required.
> >
> > select pg_column_size(B'1') as "1bit",
> > pg_column_size(B'1111') as "4bits",
> > pg_column_size(B'11111111') as "1byte",
> > pg_column_size(B'111111111111') as "12bits",
> > pg_column_size(B'1111111111111111') as "2bytes",
> > pg_column_size(B'11111111111111111') as "17bits",
> > pg_column_size(B'111111111111111111111111') as "3bytes";
> > 1bit | 4bits | 1byte | 12bits | 2bytes | 17bits | 3bytes
> > ------+-------+-------+--------+--------+--------+--------
> > 9 | 9 | 9 | 10 | 10 | 11 | 11
> > (1 row)
> >
> > Looks like there's 8 bytes of overhead as well, probably because a
> > bit string is a varlena type.
>
> Wow, that's screwed up... that's a lot more than varlena overhead:
>
> select pg_column_size('a'::text), pg_column_size(1::numeric),
> pg_column_size(3111234::numeric);
> pg_column_size | pg_column_size | pg_column_size
> ----------------+----------------+----------------
> 5 | 10 | 12
>
> Apparently it's something related to numeric.
> --
> Decibel!, aka Jim C. Nasby, Database Architect decibel(at)decibel(dot)org
> Give your computer some brain candy! www.distributed.net Team #1828
>
>

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://postgres.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Blair Bethwaite 2008-03-18 00:13:00 Is autovacuum on?
Previous Message Bruce Momjian 2008-03-17 23:32:28 Re: Moving pgstat.stat and pgstat.tmp