Unix Technical Forum

Question about VARCHAR Vs. CHAR fields

This is a discussion on Question about VARCHAR Vs. CHAR fields within the DB2 forums, part of the Database Server Software category; --> DA Morgan wrote: > Ok ok I know ... just a fantasy from an academic. ;-) Tell me about ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #21 (permalink)  
Old 02-27-2008, 05:14 AM
Knut Stolze
 
Posts: n/a
Default Re: Question about VARCHAR Vs. CHAR fields

DA Morgan wrote:

> Ok ok I know ... just a fantasy from an academic. ;-)


Tell me about it. ;-)

--
Knut Stolze
Information Integration Development
IBM Germany / University of Jena
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #22 (permalink)  
Old 02-27-2008, 05:15 AM
Phil Sherman
 
Posts: n/a
Default Re: Question about VARCHAR Vs. CHAR fields

No single correct answer but I'd use VARCHAR(15) NOT NULL and make sure
that there are no fixed length columns in the row to the right of the
varchar.

1. Searches and index construction on fixed length columns will not have
to compute where the column is in the row.

2. City is very likely to be used to construct city, state for addresses
which would require truncation anyway. If you are transmitting this data
to a terminal; transmission costs for the spaces can add up. IBM studies
done over 25 years ago demonstrated that truncating trailing blanks
before transmission was always a beneficial tradeoff. (Increased network
speeds have changed this metric but not everyone connects with a T1 or
faster link.)

3. Most city names are less than 15 chars. I'd suspect that an analysis
of name length * frequency (your specific data) would show that varchar
ends up occupying less space than fixed length.

4. NOT NULL should always be used for City unless you have a need for a
null because the length can be set to zero. This also (usually)
simplifies application programming.

Phil Sherman



hikums@gmail.com wrote:
> So, what's the recommendation for java programmers if a char(15) is
> used to store an attribute like city, and it is padded with spaces to
> the right?
>
>
>
> Knut Stolze wrote:
>
>>Jan M. Nelken wrote:
>>
>>
>>>Knut Stolze wrote:
>>>
>>>
>>>>This is certainly true, but you also have to keep in mind that more short
>>>>VARCHARs might fit on a page than (padded) CHAR values. So you could
>>>>easily have a performance benefit because less pages need to be loaded to
>>>>satisfy a query.
>>>
>>>That would be true providing that application programmer shows some
>>>restrains and will not use construct like VARCHAR(1) which will use up to
>>>6 bytes (4 bytes of length - at least on DB2 for Linux, Unix and Windows -
>>>1 byte for actual data and 1 byte for null indicator). Contrast that with
>>>CHAR(1) NOT NULL which will use exactly 1 byte.

>>
>>No question that this is indeed not very smart.
>>
>>--
>>Knut Stolze
>>Information Integration Development
>>IBM Germany / University of Jena

>
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #23 (permalink)  
Old 02-27-2008, 05:15 AM
hikums@gmail.com
 
Posts: n/a
Default Re: Question about VARCHAR Vs. CHAR fields

Thanks Phil.

Phil Sherman wrote:
> No single correct answer but I'd use VARCHAR(15) NOT NULL and make sure
> that there are no fixed length columns in the row to the right of the
> varchar.
>
> 1. Searches and index construction on fixed length columns will not have
> to compute where the column is in the row.
>
> 2. City is very likely to be used to construct city, state for addresses
> which would require truncation anyway. If you are transmitting this data
> to a terminal; transmission costs for the spaces can add up. IBM studies
> done over 25 years ago demonstrated that truncating trailing blanks
> before transmission was always a beneficial tradeoff. (Increased network
> speeds have changed this metric but not everyone connects with a T1 or
> faster link.)
>
> 3. Most city names are less than 15 chars. I'd suspect that an analysis
> of name length * frequency (your specific data) would show that varchar
> ends up occupying less space than fixed length.
>
> 4. NOT NULL should always be used for City unless you have a need for a
> null because the length can be set to zero. This also (usually)
> simplifies application programming.
>
> Phil Sherman
>
>
>
> hikums@gmail.com wrote:
> > So, what's the recommendation for java programmers if a char(15) is
> > used to store an attribute like city, and it is padded with spaces to
> > the right?
> >
> >
> >
> > Knut Stolze wrote:
> >
> >>Jan M. Nelken wrote:
> >>
> >>
> >>>Knut Stolze wrote:
> >>>
> >>>
> >>>>This is certainly true, but you also have to keep in mind that more short
> >>>>VARCHARs might fit on a page than (padded) CHAR values. So you could
> >>>>easily have a performance benefit because less pages need to be loaded to
> >>>>satisfy a query.
> >>>
> >>>That would be true providing that application programmer shows some
> >>>restrains and will not use construct like VARCHAR(1) which will use up to
> >>>6 bytes (4 bytes of length - at least on DB2 for Linux, Unix and Windows -
> >>>1 byte for actual data and 1 byte for null indicator). Contrast that with
> >>>CHAR(1) NOT NULL which will use exactly 1 byte.
> >>
> >>No question that this is indeed not very smart.
> >>
> >>--
> >>Knut Stolze
> >>Information Integration Development
> >>IBM Germany / University of Jena

> >
> >


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:18 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com