Skip to content

Category: 系统设计

具体问题,具体分析

为什么ID使用Int而不是unsigned int

最近公司把某些业务实体的ID从int32迁移到了int64。这些ID的合法数据都是大于1的,为什么不选择unsigned int64 而要选择 int64 呢? unsigned 类型相对来说可用的合法id可是大了一倍呀。 有两个原因: 1, 对齐数据类型,避免溢出或其他兼容性问题 某些数据存储,如postgress是不支持unsigned integer 类型的。比如postgresSql。 PostgresSQL Type Go Type smallint, smallserial int16(-32768 ~ 32767) int, serial int32…