What is the difference TEXT and LONGTEXT?

Asked

Viewed 17,973 times

8

I am developing a system where I will import the data from an Excel. As this data will be temporary, I intend to save the information of this imported column in format JSON at the bank.

Therefore, I was in doubt between using TEXT or LONGTEXT.

Of course this case is just one example, but there are other cases where doubt comes to mind, for example, when saving a blog post in the bank. I’d have to use TEXT or LONGTEXT?

I imagine there’s a difference just because of the names, and not because I know the technical details of the difference between one and the other.

So my question is:

  • What’s the difference between LONGTEXT and TEXT?

  • Use LONGTEXT would make my bank use more resources than use TEXT?

  • There is a difference in reading speed or performance when choosing one or the other?

  • In which cases I would have to use LONGTEXT instead of TEXT?

NOTE: In fact, I don’t even want anyone to point out in the answer what I should do with this data that I’m importing, but I would just like to know what the difference is between the two types (LONGTEXT and TEXT). Even because I know that the new version of MYSQL has the format JSON, but that’s another story, since I don’t use the new version of MYSQL*.

  • Compress the string using messagepack

  • 2

    @Marcospaulo it’s been a while since the messagepack was kind of set aside -> https://developers.google.com/protocol-buffers/ (not that I have any problem using, I just commented to science)

1 answer

12

In the Documentation you will find a lot about each type, summarizing in Sizes:

      Tipo | Tamanho Máximo
-----------+--------------------------------------
  TINYTEXT |           255 (2^ 8−1) bytes         
      TEXT |        65,535 (2^16−1) bytes = 64 KiB
MEDIUMTEXT |    16,777,215 (2^24−1) bytes = 16 MiB
  LONGTEXT | 4,294,967,295 (2^32−1) bytes =  4 GiB
  • What is the difference between LONGTEXT and TEXT? Maximum Memory Allocation (size) as above Table;

  • Would using LONGTEXT make my bank use more resources than using TEXT? Exactly, for each line in your Bank it would be necessary to book, clean, validate more memory.

  • Is there a difference in reading speed or performance when choosing one or the other? Performance differences are few in small Bases (you practically don’t care about performance on bases with tens or a few hundred results), but they can be very palpable for large Bases (1TB+), so the answer is: yes.
  • In which cases would I have to use LONGTEXT instead of TEXT? When storing more than 16Mi Chars. Storing a whole book, or all the information of a RAW image, for example.
  • 3

    I believe your answer does not answer the question exactly, there are other questions that this figure does not answer.

  • 1

    @Wallacemaxters I agree and made a good edit on the reply.

  • The difference in size between them makes me think it would be better if there were other options. If some of my texts have a size of, say, 66,000 bytes, I am obliged to opt for MEDIUMTEXT which for my case is very large. Or have two TEXT fields and handle this separation and join in the code?

  • 3

    @Reginaldorigo the only difference is how many bytes to save the length, that’s it. The answer is totally wrong in the second point. Saving a 5000 byte string in a TEXT column takes two bytes less than saving to a LONGTEXT.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.