Reputation: 843
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?
ex. 10000, 20000, 30000.... or 10k, 20k, 30k...
Upvotes: 0
Views: 1238
Reputation: 4714
The bigger question is -- would it help your project? With TINYINT
you can perform math operations on it. You can't do that with VARCHAR
, since your numbers would be a string. 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).
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.
Upvotes: 0
Reputation: 204756
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
. 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.
Generally - if it is a number - store it as number.
Upvotes: 3