Nice programing

TINYTEXT, TEXT, MEDIUMTEXT 및 LONGTEXT 최대 저장 크기

nicepro 2020. 9. 29. 18:40
반응형

TINYTEXT, TEXT, MEDIUMTEXT 및 LONGTEXT 최대 저장 크기


MySQL의 문서 , 네 개의 텍스트 종류가 있습니다 :

  1. TINYTEXT
  2. 본문
  3. MEDIUMTEXT
  4. LONGTEXT

문자 인코딩이 UTF-8이라고 가정 할 때 각 데이터 유형의 열에 저장할 수있는 최대 길이는 얼마입니까?


로부터 문서 :

      유형 | 최대 길이
----------- + -------------------------------------
  TINYTEXT | 255 (2 8 -1) 바이트
      텍스트 | 65,535 (2 16 -1) 바이트 = 64 킬로바이트
MEDIUMTEXT | 16,777,215 (2 24 -1) = 16 바이트 MiB 크기
  LONGTEXT | 4294967295 (2 32 -1) = 4 바이트 지브

수 있습니다 문자 당신의 컬럼에 저장 될 수에 따라 달라집니다 문자 인코딩 .


같은 대답의 확장

  1. SO 게시물 은 오버 헤드 및 저장 메커니즘에 대해 자세히 설명합니다.
  2. (1) 지점에서 언급했듯이 A VARCHAR은 항상 TINYTEXT 대신 사용해야합니다. 그러나 VARCHAR를 사용할 때 최대 행 크기는 65535 바이트를 초과해서는 안됩니다.
  3. 여기에 설명 된대로 http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-utf8.html , utf-8의 경우 최대 3 바이트.

이것은 빠른 결정을위한 대략적인 추정 표입니다!

  1. 따라서 최악의 경우 가정 (utf-8 char 당 3 바이트)에서 최상의 경우 (utf-8 char 당 1 바이트)
  2. 영어가 단어 당 평균 4.5 자라고 가정합니다.
  3. x는 할당 된 바이트 수입니다.

더블 엑스

      Type | A= worst case (x/3) | B = best case (x) | words estimate (A/4.5) - (B/4.5)
-----------+---------------------------------------------------------------------------
  TINYTEXT |              85     | 255               | 18 - 56
      TEXT |          21,845     | 65,535            | 4,854.44 - 14,563.33  
MEDIUMTEXT |       5,592,415     | 16,777,215        | 1,242,758.8 - 3,728,270
  LONGTEXT |   1,431,655,765     | 4,294,967,295     | 318,145,725.5 - 954,437,176.6

Chris V의 답변도 참조하십시오 : https://stackoverflow.com/a/35785869/1881812


@ Ankan-Zerob의 도전으로 떠오르면, 이것은 단어로 측정 된 각 텍스트 유형에 저장할 수있는 최대 길이에 대한 나의 추정치입니다 .

      Type |         Bytes | English words | Multi-byte words
-----------+---------------+---------------+-----------------
  TINYTEXT |           255 |           ±44 |              ±23
      TEXT |        65,535 |       ±11,000 |           ±5,900
MEDIUMTEXT |    16,777,215 |    ±2,800,000 |       ±1,500,000
  LONGTEXT | 4,294,967,295 |  ±740,000,000 |     ±380,000,000

In English, 4.8 letters per word is probably a good average (eg norvig.com/mayzner.html), though word lengths will vary according to domain (e.g. spoken language vs. academic papers), so there's no point being too precise. English is mostly single-byte ASCII characters, with very occasional multi-byte characters, so close to one-byte-per-letter. An extra character has to be allowed for inter-word spaces, so I've rounded down from 5.8 bytes per word. Languages with lots of accents such as say Polish would store slightly fewer words, as would e.g. German with longer words.

Languages requiring multi-byte characters such as Greek, Arabic, Hebrew, Hindi, Thai, etc, etc typically require two bytes per character in UTF-8. Guessing wildly at 5 letters per word, I've rounded down from 11 bytes per word.

CJK scripts (Hanzi, Kanji, Hiragana, Katakana, etc) I know nothing of; I believe characters mostly require 3 bytes in UTF-8, and (with massive simplification) they might be considered to use around 2 characters per word, so they would be somewhere between the other two. (CJK scripts are likely to require less storage using UTF-16, depending).

This is of course ignoring storage overheads etc.


This is nice but doesn't answer the question:

"A VARCHAR should always be used instead of TINYTEXT." Tinytext is useful if you have wide rows - since the data is stored off the record. There is a performance overhead, but it does have a use.

참고URL : https://stackoverflow.com/questions/13932750/tinytext-text-mediumtext-and-longtext-maximum-storage-sizes

반응형