0

In MySQL documentation you can find that CHAR datatype has no preceding byte with string length.

In contrast VARCHAR datatype has 1 or 2 preceding bytes where string length is stored. Which is understandable. Database engine needs to know what is the string length in order to read it.

How does database engine know what is CHAR datatype length? What logic/algorithm is behind it?

Marcin Badtke
  • 599
  • 5
  • 9
  • 2
    The value length for CHAR is defined in the table structure and does not need in repeated length specifying. – Akina Jun 02 '22 at 05:33
  • @Akina - do you suggest that MySQL has 2 algorithms to deal with character datatypes: #1 for CHAR datatype where it looks for string length in system tables and #2 for VARCHAR where it looks for string length in datablock? – Marcin Badtke Jun 02 '22 at 05:51
  • You might wonder how db recognises any datatype, my view is this question is off topic for this site. https://dev.mysql.com/doc/internals/en/ may have the answer. Personally I don't see how knowing this stuff is useful. – P.Salmon Jun 02 '22 at 06:06
  • *do you suggest that MySQL has 2 algorithms to deal with character datatypes* These are two different datatypes. You confuse that both stores string data - forget about this, this is your interpretation only. They're DIFFERENT DATATYPE, and they're processed differently. – Akina Jun 02 '22 at 07:30

0 Answers0