1

关于 MySQL 建表主键用自增还是 uuid 的问题

 2 years ago
source link: https://www.v2ex.com/t/821780
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  MySQL

关于 MySQL 建表主键用自增还是 uuid 的问题

  daoqiongsi1101 · 1 天前 · 3439 次点击

关于 MySQL 建表主键 id 字段的类型,目前有这几种:

  1. 一个自增数字作为主键 id
  2. 一个无序的 uuid 作为 id
  3. 一个有序的 uuid 作为 id
  4. 一个业务 uuid (无序)作为 id ,一个自增字段 incr_id

InnoDB 引擎,主键 id 有序能利用其优势。

第 1 种,对于敏感的数据,容易根据 id 增长暴露增量;

第 2 种,没利用到 B+ Tree 的特性;

第 3 种,要引入 snowflake 等算法生成器;

第 4 种,其实是第 2 种的变体,加一个 incr_id 自增字段,在分页的时候用到

大家讨论一下,在 2021 年,那种主键 id 类型是推荐的?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK