简体   繁体   English

Mysql TINYINT和VARCHAR性能

[英]Mysql TINYINT & VARCHAR performance

I have a column build in mysql db, it store the value - 10000 in TINYINT , what if I change it to 10k VARCHAR which one will be better performance? 我在mysql db中建立了一个列,它在TINYINT存储值TINYINT ,如果我将其更改为10k VARCHAR会更好呢?

ex. 例如 10000, 20000, 30000.... or 10k, 20k, 30k... 10000,20000,30000 ....或10k,20k,30k ...

If you are just selecting the value then it doesn't matter. 如果您只是选择该值,那就没关系。

But if you are using it in a where condition then the performance will be better using an int . 但是,如果您在where条件下使用它,那么使用int可以提高性能。 Example: 例:

select * from your_table
where your_column > 1000

will only work if the column is an int and you don't need to convert it back to a number. 仅当int且您无需将其转换回数字时才有效。

Generally - if it is a number - store it as number. 通常,如果是数字,则将其存储为数字。

The bigger question is -- would it help your project? 更大的问题是-对您的项目有帮助吗? With TINYINT you can perform math operations on it. 借助TINYINT您可以对其执行数学运算。 You can't do that with VARCHAR , since your numbers would be a string. 您不能使用VARCHAR ,因为您的数字将是一个字符串。 Sure you could manipulate the string into a number, but that'll cost you in performance as well as the need to make extra code (which can unnecessarily complicate the SQL or other language). 当然,您可以将字符串处理成一个数字,但这会降低性能,并增加额外的代码(这可能会使SQL或其他语言不必要地复杂化)。

If you're going to make a value be a number -- then by all means make it an integer . 如果您要将值设为数字-则务必将其设为整数 There's a reason really really smart people made a difference between string's & int's. 有一个非常聪明的人在string和int之间有所作为的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM