As I said, I found a strange phenomenon when referring to other people's projects,
some people's table columns (qualified for the title) use char instead of tinyint, such as
create table A(
id int not null auto_increment,
a_seq char(9) comment 'The first one is 1, 2, 3 (national, private, foreign)'
a_type char(1) comment '0 is normal, 1 is disable'
a_status char(1) comment '0 is visible, 1 is not'
)
For a_type
and a_status
, both char(1) and tinyint(1) are one byte, and the comparison speed of numeric characters and numbers may be as fast, so the difference between the two is not very big.
So for a_seq
, why not use int for storage? int only takes up 4 bytes, but char(9) takes up 9 bytes. If you add a UNIQUE
index to a_seq
, doesn't char(9) take up space and be slow?
To add, I also saw someone store the year (2020, 2021) in char(4) instead of shortint
Can anyone tell me the reason for this empirically, as I'm getting confused by this.