Page 1 of 1
VARCHAR
Posted: Wed Feb 06, 2008 2:14 am
by denisw
Hi,
I would like to check if I define a field with type Varchar(250), and the data entered is only 10 chars, does it take up the space as much as 250 chars ?
if it takes fewer space, is it advisable to specify any Varchar typed field to the largest length possible ?
thanks.
Re: VARCHAR
Posted: Wed Feb 06, 2008 3:09 am
by Kieran Huggins
varchar fields are *always* allocated the max width since rows are typically written in contiguous disk clusters for performance reasons. I think only blobs (including text) are variable length, and stored elsewhere on disk.
Incidentally, this strategy can increase row load times if there's one or more blobs in a single row. Some people avoid loading them unless they're needed. In order to do this you'll need to specify the columns you want loaded, since * loads them all.
Re: VARCHAR
Posted: Wed Feb 06, 2008 4:02 am
by onion2k
Kieran Huggins wrote:varchar fields are *always* allocated the max width since rows are typically written in contiguous disk clusters for performance reasons. I think only blobs (including text) are variable length, and stored elsewhere on disk.
That's wrong. CHAR fields store the string padded with spaces to the number of characters defined, VARCHAR allocates the length of the string as the first one or two bytes followed by the string itself. They're not padded.
http://dev.mysql.com/doc/refman/5.0/en/char.html
Re: VARCHAR
Posted: Wed Feb 06, 2008 4:07 am
by Kieran Huggins
I stand happily corrected!