Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why if I create a varchar(65535), I get a mediumtext?

Does a mediumtext and a varchar(65535) are the same thing ? What I mean here is do they both store the data directly in the table or do the mediumtext type is storing a pointer ? I'm asking this because if I try to create a varchar(65535) it is automatically transform into a mediumtext (if the length is bigger than 21811 actually).


I've got another related question which is:

I've got some fields in a table that I want to be able to store a lot of characters (around 10'000). But in reality, it will almost all the time store no more than 10 characters.

So my question is, do I need to use a text or a varchar(10000) type for best performance ?

I believe a varchar type is more appropriate for this case.

Thanks in advance for your answers.

Edit

The thing I don't understand is why they say that since mysql 5.0.3, we can create a varchar(65535) but when we try to do this, it convert it to a mediumtext. For me the difference between varchar and text (mediumtext include) is the way how they are store (using a pointer or not). So why do they say that we can create varchar with a length of 65535 if we can't?

like image 416
Nicolas BADIA Avatar asked Oct 01 '11 11:10

Nicolas BADIA


1 Answers

I'm answering to my own question:

That's because I'm using a multi-byte character. If you use an utf-8 collation, you will not be able to create a varchar with about more than 21000 chars. But if you use ascii, you will.

like image 51
Nicolas BADIA Avatar answered Oct 11 '22 07:10

Nicolas BADIA