Re: [HACKERS] varchar/char size

From: Mattias Kregert <matti(at)algonet(dot)se>
To: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
Cc: PostgreSQL-development <hackers(at)postgreSQL(dot)org>
Subject: Re: [HACKERS] varchar/char size
Date: 1998-01-09 13:26:43
Message-ID: 34B62593.68FB309@algonet.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Bruce Momjian wrote:
>
> Does someone want to remind me why we allocate the full size for char()
> and varchar(), when we really can just allocate the size of the given
> string?
>
> I relize char() has to be padded, but why varchar()?
>
> In my experience, char() is full size as defined by create, and
> varchar() is the the size of the actual data in the field, like text,
> but with a pre-defined limit.

Is CHAR padded on disk? Of course it should be padded for
representation, but for storage, couldn't it be stored just like
TEXT or VARCHAR? Before storing, it could be trimmed, and when
read from storage, it could be padded with spaces on the right.

Btw, why is VARCHAR not simply an alias for TEXT, with maxlen added?
Shouldn't these types be the same internally, but with maxlen checked
for VARCHAR in the parser and maxlen set to "infinite"(-1?) for TEXT?
Or perhaps CHAR could be put into the same type also?

If we have a type called VARTEXT(int maxLen, bool doPaddingProcessing):

VARCHAR(10) becomes VARTEXT(10, false) // 10 chars, no padding
TEXT becomes VARTEXT(0, false) // infinite length, no padding
CHAR(10) becomes VARTEXT(10, true) // 10 chars, padded

Would not this be easier to handle than three different types? This
type stuff would be handled in the parser. There would be only one
storage function, which could do any kind of coding to make the VARTEXT
take as little space as possible on disk.
Perhaps it would (in some cases) be good to have the possibility to
specify compression of the text. That could be another bool attribute
to VARTEXT, used by "COMPRESSED VARCHAR()" or "COMPRESSED TEXT" so that
people can squeeze the maximum out of their disk space.

A related question: Is it possible to store tuples over more than one
block? Would it be possible to split a big TEXT into multiple blocks?

/* m */

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Darren King 1998-01-09 14:43:52 Re: [HACKERS] varchar/char size
Previous Message Bruce Momjian 1998-01-09 03:55:03 subselects