Field size takes total defined value?

Asked

Viewed 728 times

4

If the maximum size of a field of type VARCHAR is 65535 (ocupa 65KB), it will always take up a space of 65KB in the database for each line even if I put less text in it?

EXAMPLE: a field VARCHAR(65000) occupies 65kb even if it is filled only with 200 characters and not the 65000? Or the size is dynamic?

  • Varchar no, see the answer of that question

  • Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site.

2 answers

5


If the maximum size of a field of type VARCHAR is 65535 (occupies 65KB), it will always take up a 65KB space in the database for each line even if I put less text in it?

No, it will occupy essentially only the space occupied by the text. It’s a little more complicated than that, but it’s almost just that, just don’t think that if the text has 10 characters it will take 10 bytes. It depends on the encoding used, of the characters used effectively, has control information. Not to mention that there may be some other cost because of tricks that the database can use for optimizations. It will take more than 10 bytes, but not much more, maybe 30 at most. But if the text has 1000 characters depending on the case it will take 1012, for example.

Can use without fear. only the CHAR is that it occupies the space, using or not.

See more.

4

Yes the size is dynamic. VARCHAR only considers the space used by the column and not the total storage of the column. This is not to say that you should add high values in a field, that is, it is important to know that you should limit the size of a column of variable length (column you can set value).

Even if the column is variable and the storage space used is variable the MySQL will allocate memory in fixed blocks to store values. For example Varchar(200) use more memory than Varchar(5), remembering that this is not a storage space problem.

Value in bytes used per character:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.