Home  >  Q&A  >  body text

mysql - 表的主键都是varchar(64),有什么不好?

见识到一个java项目,mysql数据库,所有表的主键都是varchar(64)

ringa_leeringa_lee2742 days ago894

reply all(4)I'll reply

  • 怪我咯

    怪我咯2017-04-17 15:08:53

    Compared to int, varchar takes up more disk space, has more disk IO, and has more memory bandwidth. This is especially obvious in innodb. The leaf page of the secondary index of the innodb table must store the value of the primary key. If the primary key is varchar, the size of the secondary index will be larger. Moreover, the varchar primary key will be slower in comparison. It is easy to send non-sequential insertion of data during insertion, resulting in fragmentation. The index tree efficiency is lower than that of int

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 15:08:53

    This is a sign of laziness!

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 15:08:53

    Very wasteful and unprofessional.

    If it is char() type, the value given is 5. Then regardless of whether there is a value in the field, even null will occupy 5×当前数据库编码字节. varchar() will first use one byte to record the maximum range of the type. If no value is passed, it will only record the first byte. If it is passed, the content within the maximum range of the value will be stored.

    The hard disk space occupied by each record of the remaining fields will be discussed separately.

    reply
    0
  • 阿神

    阿神2017-04-17 15:08:53

    Everything said above is correct
    Maybe the content he recorded is UUID
    Many jsp programming libraries are like this when designing libraries, I don’t know why

    reply
    0
  • Cancelreply