Re: [HACKERS] varchar() change - Mailing list pgsql-hackers

From Vadim B. Mikheev
Subject Re: [HACKERS] varchar() change
Date
Msg-id 34B46971.5A593F09@sable.krasnoyarsk.su
Whole thread Raw
In response to varchar() change  (Bruce Momjian <maillist@candle.pha.pa.us>)
List pgsql-hackers
Bruce Momjian wrote:
>
> Let me go over the issues with the varchar() change.
>
> char() will continue to store full bytes, while varchar() function like
> text, but with a limited length.
>
> Now, pg_attribute.attlen is access everywhere, trying to find out how
> long the data field is.  With text, the length is -1, but with varchar
> currently, it is the max length, and hence, it has to store all those
> bytes.
>
> Now, my idea is to add a new pg_attribute column called 'attmaxlen'
> which will hold the maximum length of the field.  char() and varchar()
> will use this field, and the code will have be changed.  Cases where
> attlen is referenced to determine data size will continue to use -1, but
> references to all functions that create a data entry will use the
> attmaxlen.  I see 124 references to attlen in the code.  Not too bad.
> Most are obvious.

Ok. I agreed that we have to add new column to pg_attribute, but I recommend

1. use some other name - not attmaxlen: this field could be used for
   NUMBER, etc and "maxlen" is not good name for storing precision, etc
   (atttspec ?)
2. use -2 for varchar: let's think about attlen -1 as about "un-limited"
   varlena, and about attlen -2 as about "limited" one, with maxlen
   specified in att???. I don't see problem with -2 - just new case of
   switch (attlen) - and this will allow leave text (-1) untouched
   (or you will have to store -1 in att??? for text to differentiate
    text from varchar)...
   Hmm, ... on the other hand, we could check atttype before switch(attlen)
   in heaptuple.c and other places - don't know what's better...

Vadim

pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] rollback varchar change
Next
From: "Vadim B. Mikheev"
Date:
Subject: Re: [HACKERS] rollback varchar change