From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dominique Devienne <ddevienne@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: byte-size of column values
Date: Tue, 18 Oct 2022 12:04:48 -0400
Message-ID: <2655106.1666109088@sss.pgh.pa.us> (raw)
In-Reply-To: <CAFCRh-8gUgsZt8Yg7c_k2Es7wPPQwhqghGJO3V7azcSFfj+BRg@mail.gmail.com>
References: <CAFCRh-8gUgsZt8Yg7c_k2Es7wPPQwhqghGJO3V7azcSFfj+BRg@mail.gmail.com>
Dominique Devienne <ddevienne@gmail.com> writes:
> Hi. I'm surprised by the result for bit(3) and char, when calling
> pg_column_size().
> Why 6, instead of 1? The doc does mention 5-8 bytes overhead, but I
> expected those for varying bit, not fixed-sized bit typed values. How
> come?
Your expectation is incorrect. Postgres always treats these types
as variable-length, whether or not the column has a length constraint.
Thus, there's always a header to store the actual length. That can
be either 1 or 4 bytes (I think the doc you are looking at might be
a little out of date on that point).
Because of the popularity of variable-width character encodings,
a column declared as N characters wide isn't necessarily a fixed
number of bytes wide, making it a lot less useful than you might
think to have optimizations for fixed-width storage. Between that
and the fact that most Postgres developers regard CHAR(N) as an
obsolete hangover from the days of punched cards, no such
optimizations have been attempted.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, ddevienne@gmail.com
Subject: Re: byte-size of column values
In-Reply-To: <2655106.1666109088@sss.pgh.pa.us>
References: <CAFCRh-8gUgsZt8Yg7c_k2Es7wPPQwhqghGJO3V7azcSFfj+BRg@mail.gmail.com> <2655106.1666109088@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox