jkeuhlen
jkeuhlen

Reputation: 4527

Does VARCHAR ever require more than two bytes of extra storage?

I've read through several other questions on here and in the relevant mysql documentation but haven't found a sufficient answer.

From the docs,

A column uses one length byte if values require no more than 255 bytes, two length bytes if values may require more than 255 bytes.

If I set VARCHAR(255), only one length byte is used. If I set VARCHAR(256), two length bytes are used. What happens if I used VARCHAR(65535), the maximum size allowed by the datatype? Are only two length bytes still used? Or is it higher now? If this is the case, where are the other transitions for the length byte sizes.

Upvotes: 0

Views: 180

Answers (1)

Evert
Evert

Reputation: 99851

2^16 = 65536

So 2 bytes is enough to store numbers up to 65535.

Upvotes: 1

Related Questions