Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: 关于 text 和 varchar 类型选择

Regarding TiDB table design and usage specifications, the choice between text and varchar is not clear here.
Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: 关于 text 和 varchar 类型选择
Regarding TiDB table design and usage specifications, the choice between text and varchar is not clear here.
Large fields themselves are not recommended to be stored in the database. But I don’t understand which part is unclear?
The previous version didn’t support it very well…
If you have this requirement, you can use the new version to do a POC test.
This is also someone else’s suggestion, and I think it can be used now.
If the product supports both MySQL and TiDB databases, it is recommended to use text when creating tables. Using varchar(10000) will result in an error in MySQL… personal experience…
The maximum length of MySQL varchar is 65535, so 10000 should be fine.
Under the utf8mb4 character set encoding, one character occupies 4 bytes. I understand that varchar 10000 does not exceed the 6MB limit, right? Text itself does not have this limit, which is quite concerning.
There is more than one field in this table~
Look at this table, it’s both long and wide~
It’s not a large field either. For example, in our business, this field stores the values of a multi-select attribute, so we don’t know how much data it can hold. Some developers used to directly use varchar(max), but here there’s no max, so they use varchar(10000) or something like that. In reality, it might only use a length of a few dozen, but theoretically, someone could select multiple values reaching a length of tens of thousands.
Using varchar for very large fields is not suitable; it will directly report an error when inserting.
Calculate the max length to know how big it is, and make adjustments. It is generally not recommended to store large fields in a relational database.
No need to calculate, we are working on a project. Just run the script on the project to see if it exceeds the length. Haha, if it exceeds, just change it to text.
It is still recommended to set it according to business needs. Setting it too large is not very good.
Sometimes it’s hard to predict this thing, and it might throw an error one day. It will be quite troublesome to fix it then.
TiDB has a maximum size limit of 6MB for a single row and column, which is also to prevent rows from becoming too large.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.