MySQL: Large VARCHAR vs. TEXT?

后端 未结 8 1380
庸人自扰
庸人自扰 2020-11-22 09:21

I\'ve got a messages table in MySQL which records messages between users. Apart from the typical ids and message types (all integer types) I need to save the actual message

8条回答
  •  一生所求
    2020-11-22 10:13

    The preceding answers don't insist enough on the main problem: even in very simple queries like

    (SELECT t2.* FROM t1, t2 WHERE t2.id = t1.id ORDER BY t1.id) 
    

    a temporary table can be required, and if a VARCHAR field is involved, it is converted to a CHAR field in the temporary table. So if you have in your table say 500 000 lines with a VARCHAR(65000) field, this column alone will use 6.5*5*10^9 byte. Such temp tables can't be handled in memory and are written to disk. The impact can be expected to be catastrophic.

    Source (with metrics): https://nicj.net/mysql-text-vs-varchar-performance/ (This refers to the handling of TEXT vs VARCHAR in "standard"(?) MyISAM storage engine. It may be different in others, e.g., InnoDB.)

提交回复
热议问题