MySQL char vs.int [英] MySQL char vs. int
问题描述
我目前正在课堂上讨论MySQL中的数据类型char
和int
.
我们有一个包含8个个人号码的电话号码.但是,我们找不到每种优点和缺点.
I'm currently having a discussion in my class about the datatypes char
and int
in MySQL.
We have a phone number of 8 individual numbers. However, we can't find any pros and cons for each of them.
我们应该使用char
类型还是int
类型,为什么?
Should we use the char
type or the int
type, and why?
推荐答案
如果具有固定大小,则可以使用char(8)
-> 8B,mysql在固定大小字段上的运行速度要快得多,但是如果选择int
-> 4B可以节省空间,而且如果在该字段上有索引,它将比char更快地工作.
If you have a fixed size then you can use char(8)
-> 8B , mysql works much faster with fixed size fields, but if you chose int
-> 4B you will save space and also if you will have a index on that field it will work faster then the char.
您可以使用char(8)和int做一个简单的基准测试写入和读取的速度
You can do a simple benchmark to test the speed of writes and reads using char(8) and int
如果具有固定大小,则使用 varchar或varbinary 这样的可变长度类型没有没有要点,因为性能会降低
There is no point in using variable length type like varchar or varbinary if you have a fixed size because performance will decrease
这篇关于MySQL char vs.int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!