Unix Technical Forum

How are mysql column size declaration influence performance.

This is a discussion on How are mysql column size declaration influence performance. within the MySQL forums, part of the Database Server Software category; --> Hi, I have a basic question. If i declare a column as VARCHAR(20) even though i am sure that ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-16-2008, 02:40 PM
bssarath@gmail.com
 
Posts: n/a
Default How are mysql column size declaration influence performance.

Hi,

I have a basic question.
If i declare a column as VARCHAR(20) even though i am sure that it is
not going to contain values of length greater than 15, Will this
affect the performance of mysql query retrieval???
If so how?
Can any one please explain.

Thanks,
Sarath

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-16-2008, 02:40 PM
petethebloke@googlemail.com
 
Posts: n/a
Default Re: How are mysql column size declaration influence performance.

On 15 May, 07:29, bssar...@gmail.com wrote:
> Hi,
>
> I have a basic question.
> If i declare a column as VARCHAR(20) even though i am sure that it is
> not going to contain values of length greater than 15, Will this
> affect the performance of mysql query retrieval???
> If so how?
> Can any one please explain.
>
> Thanks,
> Sarath


http://dev.mysql.com/doc/refman/5.0/en/char.html
My understanding is that the data is truncated so it will be of no
consequence.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-16-2008, 02:40 PM
petethebloke@googlemail.com
 
Posts: n/a
Default Re: How are mysql column size declaration influence performance.

On 15 May, 14:27, "petethebl...@googlemail.com"
<petethebl...@googlemail.com> wrote:
> On 15 May, 07:29, bssar...@gmail.com wrote:
>
> > Hi,

>
> > I have a basic question.
> > If i declare a column as VARCHAR(20) even though i am sure that it is
> > not going to contain values of length greater than 15, Will this
> > affect the performance of mysql query retrieval???
> > If so how?
> > Can any one please explain.

>
> > Thanks,
> > Sarath

>
> http://dev.mysql.com/doc/refman/5.0/en/char.html
> My understanding is that the data is truncated so it will be of no
> consequence.


Sorry. Phrased that wrongly.
The storage space is shortened. The data is not truncated. Read the
page I pointed to.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-16-2008, 02:40 PM
Michael Austin
 
Posts: n/a
Default Re: How are mysql column size declaration influence performance.

bssarath@gmail.com wrote:
> Hi,
>
> I have a basic question.
> If i declare a column as VARCHAR(20) even though i am sure that it is
> not going to contain values of length greater than 15, Will this
> affect the performance of mysql query retrieval???
> If so how?
> Can any one please explain.
>
> Thanks,
> Sarath
>


No.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-18-2008, 11:02 PM
John Murtari
 
Posts: n/a
Default Re: How are mysql column size declaration influence performance.

Sarath,

> If i declare a column as VARCHAR(20) even though i am sure that it is
> not going to contain values of length greater than 15, Will this
> affect the performance of mysql query retrieval???
> If so how?
> Can any one please explain.


When you do a search, MySQL has to find its way to the data
in every row. If your data rows are fixed in length (no use of
varchar or other variable length fields) the search "can" be faster
and indexing can be faster.

http://dev.mysql.com/doc/refman/5.0/en/data-size.html

--
John
__________________________________________________ _________________
John Murtari Software Workshop Inc.
jmurtari@following domain 315.635-1968(x-211) "TheBook.Com" (TM)
http://thebook.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 05-18-2008, 11:02 PM
Michael Austin
 
Posts: n/a
Default Re: How are mysql column size declaration influence performance.

John Murtari wrote:
> Sarath,
>
>> If i declare a column as VARCHAR(20) even though i am sure that it is
>> not going to contain values of length greater than 15, Will this
>> affect the performance of mysql query retrieval???
>> If so how?
>> Can any one please explain.

>
> When you do a search, MySQL has to find its way to the data
> in every row. If your data rows are fixed in length (no use of
> varchar or other variable length fields) the search "can" be faster
> and indexing can be faster.
>
> http://dev.mysql.com/doc/refman/5.0/en/data-size.html
>


Then, what you are saying is that he should use all CHAR() definitions.

Unless they have finally fixed this, the retrieval of data may have a
higher CPU cost, because of the way the add/strip trailing spaces,
making an ANSI style CHAR() retrieval impossible.

In the **ANSI standard data-types**, if you store 15 bytes of data in a
VARCHAR(20) field, you expect to have 15 characters returned. If you
store 15 bytes of data in a CHAR(20) field - you expect to get your 15
bytes + 5 bytes space-filled data. Geniuses at MYSQL made it so it
would only return the 15 CHAR bytes you entered. Obviously they have
never had to deal with COBOL programming - that is still alive and well
in most major and a lot of minor shops around the world.

At this point let's just make up our own definitions for terms like
data-type and what is and what does. But because this behavior is
"documented", it makes it somehow okay.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 05-24-2008, 07:09 AM
bssarath@gmail.com
 
Posts: n/a
Default Re: How are mysql column size declaration influence performance.

On May 18, 1:28 am, Michael Austin <maus...@firstdbasource.com> wrote:
> John Murtari wrote:
> >Sarath,

>
> >> If i declare a column as VARCHAR(20) even though i am sure that it is
> >> not going to contain values of length greater than 15, Will this
> >> affect the performance of mysql query retrieval???
> >> If so how?
> >> Can any one please explain.

>
> > When you do a search, MySQL has to find its way to the data
> > in every row. If your data rows are fixed in length (no use of
> > varchar or other variable length fields) the search "can" be faster
> > and indexing can be faster.

>
> >http://dev.mysql.com/doc/refman/5.0/en/data-size.html

>
> Then, what you are saying is that he should use all CHAR() definitions.
>
> Unless they have finally fixed this, the retrieval of data may have a
> higher CPU cost, because of the way the add/strip trailing spaces,
> making an ANSI style CHAR() retrieval impossible.
>
> In the **ANSI standard data-types**, if you store 15 bytes of data in a
> VARCHAR(20) field, you expect to have 15 characters returned. If you
> store 15 bytes of data in a CHAR(20) field - you expect to get your 15
> bytes + 5 bytes space-filled data. Geniuses at MYSQL made it so it
> would only return the 15 CHAR bytes you entered. Obviously they have
> never had to deal with COBOL programming - that is still alive and well
> in most major and a lot of minor shops around the world.
>
> At this point let's just make up our own definitions for terms like
> data-type and what is and what does. But because this behavior is
> "documented", it makes it somehow okay.


Thank you guys, i got the answer.

Sarath
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 04:25 PM.


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