gpt4 book ai didi

mysql - 在大表中使用用户 ID 作为主键

转载 作者:行者123 更新时间:2023-11-29 11:29:27 26 4
gpt4 key购买 nike

我有一个表(id(PK,UNIQUE),user_id,[此处的其他列]),其中包含大量(100k+)用户订单,其中每个用户只能访问已设置他的user_id的订单。

我想知道使用 user_id 作为主键会如何影响该数据库上 SELECT 查询的性能。是否有任何有效的解决方案可以在单个 InnoDB 表中维护大量与用户绑定(bind)的行(每个订单有一个所有者)?

最佳答案

如果大多数查询都包含 user_id 的特定值,则效率更高:

PRIMARY KEY(user_id, id),  -- to get the benefit of 'clustering' around user_id
INDEX(id) -- to make AUTO_INCREMENT happy

关于mysql - 在大表中使用用户 ID 作为主键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37657933/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com