티스토리 뷰

반응형
 

MySQL :: MySQL 8.0 Reference Manual :: 13.3.2 The CHAR and VARCHAR Types

13.3.2 The CHAR and VARCHAR Types The CHAR and VARCHAR types are similar, but differ in the way they are stored and retrieved. They also differ in maximum length and in whether trailing spaces are retained. The CHAR and VARCHAR types are declared with a l

dev.mysql.com

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.
In contrast to CHAR, VARCHAR values are stored as a 1-byte or 2-byte length prefix plus data. The length prefix indicates the number of bytes in the value. 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.

공식문서를 보면, VARCHAR의 경우 항상 길이를 표현하기 위한 byte가 접두사처럼 붙는다고 한다.

2진법으로 따졌을 때, 부호 없이 1바이트로 나타낼 수 있는 범위는 255까지고 2바이트로 나타낼 수 있는 범위는 65,535까지이므로, VARCHAR(255)는 접두사로 1바이트를 사용하지만 VARCHAR(256)부터는 접두사로 2바이트를 사용하게 된다. 결국 row 수가 많아질수록 불필요한 낭비가 커지기 때문인 듯!

댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함