From: | Manfred Koizar <mkoi-pg(at)aon(dot)at> |
---|---|
To: | elein <elein(at)varlena(dot)com> |
Cc: | CSN <cool_screen_name90001(at)yahoo(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: int1? types? |
Date: | 2003-10-11 01:42:57 |
Message-ID: | 6dmeov8g9ouo4ek8qberdlvmjit93vbt00@email.aon.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, 10 Oct 2003 16:53:55 -0700, elein <elein(at)varlena(dot)com> wrote:
>I don't think that you can create a genuine one byte datatype.
>The resulting type would probably be four bytes long, even if
>you create a one byte by-value data type.
Column values are not *expanded* to multiples of four bytes, they are
*aligned* according to their datatype (cf. pg_type.typalign).
Not counting heap tuple headers, we get the following offsets and
lengths:
CREATE TABLE a (
c1 "char" NOT NULL, -- offset 0
c2 "char" NOT NULL, -- offset 1
c3 "char" NOT NULL, -- offset 2
c4 "char" NOT NULL -- offset 3
); -- size = 4
CREATE TABLE b (
c1 bool NOT NULL, -- offset 0
c2 int2 NOT NULL, -- offset 2
c3 bool NOT NULL, -- offset 4
c4 int NOT NULL, -- offset 8
c5 bool NOT NULL, -- offset 12
c6 char(1) NOT NULL -- offset 16
); -- size = 24
Here c6 consists of a four byte length followed by one data byte
(unless the character needs a multibyte representation), the length
has to be aligned on a four byte boundary and the whole row is padded
to a multiple of MAXALIGN, typically four on a 32 bit machine. So we
have three padding bytes before c6 and three padding bytes after c6.
CREATE TABLE bb (
c6 char(1) NOT NULL, -- offset 0
c1 bool NOT NULL, -- offset 5
c3 bool NOT NULL, -- offset 6
c5 bool NOT NULL, -- offset 7
c4 int NOT NULL, -- offset 8
c2 int2 NOT NULL -- offset 12
); -- size = 16
Servus
Manfred
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2003-10-11 01:49:05 | Re: go for a script! / ex: PostgreSQL vs. MySQL |
Previous Message | Joe Conway | 2003-10-11 01:28:08 | Re: int1? types? |