Length of field occupies total value defined?

4

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

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

    
asked by anonymous 26.05.2017 / 19:14

2 answers

5
  

If the maximum size of a field of type VARCHAR is 65535 (occupies 65KB), will it always occupy a space of 65KB in the database for each row 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 that's almost it. Just do not think that if the text has 10 characters it will occupy 10 bytes. It depends on the encoding used, of the characters used effectively, has the control information. Not to mention that there may be some other costs because of tricks that the database can use for optimizations. It will take up 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 occupy 1012, for example.

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

See more .

    
26.05.2017 / 19:27
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 length of a column of variable length (column you can define 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) will use more memory than Varchar(5) , remembering that this is not a storage space problem.

Value in bytes used per character:

    
26.05.2017 / 19:31