MySQL: Large VARCHAR vs. TEXT?

后端 未结 8 1445
庸人自扰
庸人自扰 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:14

    There is a HUGE difference between VARCHAR and TEXT. While VARCHAR fields can be indexed, TEXT fields cannot. VARCHAR type fields are stored inline while TEXT are stored offline, only pointers to TEXT data is actually stored in the records.

    If you have to index your field for faster search, update or delete than go for VARCHAR, no matter how big. A VARCHAR(10000000) will never be the same as a TEXT field bacause these two data types are different in nature.

    • If you use you field only for archiving
    • you don't care about data speed retrival
    • you care about speed but you will use the operator '%LIKE%' in your search query so indexing will not help much
    • you can't predict a limit of the data length

    than go for TEXT.

提交回复
热议问题