What is the disadvantage to using a MySQL longtext sized field when every entry will fit within a mediumtext sized field?

拟墨画扇 提交于 2019-11-27 12:03:47

问题


What is the disadvantage to using a MySQL longtext sized field when every entry will fit within a mediumtext sized field?

The reason I am asking is because I have some longtext sized fields and recently realized they are much too large, but then struggled with motivating myself to make the minute change because "what's the harm?" hence the question.


回答1:


The only storage size difference is the number of bytes allocated for the "how many bytes is this field" number. From the fine manual:

TINYTEXT    L + 1 bytes, where L < 2^8  
TEXT        L + 2 bytes, where L < 2^16
MEDIUMTEXT  L + 3 bytes, where L < 2^24
LONGTEXT    L + 4 bytes, where L < 2^32

So a longtext will use one more byte than mediumtext to store the same text. There is a bit more information in the Data Type Storage Requirements section of the manual and some more in the The BLOB and TEXT Types section.

There's no practical difference between the four TEXT types.




回答2:


Mysql uses temporary tables a lot of times to execute queries. So the disadvantage of having large sized field is that MySql will reserve that much space for the column.

You will have slow execution with same data if you have that column marked at longtext compare to mediumtext



来源:https://stackoverflow.com/questions/7314682/what-is-the-disadvantage-to-using-a-mysql-longtext-sized-field-when-every-entry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!