V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
kanonlee207
V2EX  ›  程序员

postgresql 分区表 主键索引问题

  •  
  •   kanonlee207 · 1 天前 · 398 次点击

    pg 分区表如果不设主键,而设置唯一索引,会对性能有什么影响吗, 主要是递增序列 id 字段很多时候都不在分区字段里,这种情况应该怎么处理比较好.

    比如有一个用户道具分区表, 有字段 id, user_id, item_id, amount. 通过 user_id 来分区,这种情况怎么建立索引好. 是建立 user_id,item_id 的复合主键,还是唯一索引, id 递增序列该怎么处理. 主要查询是通过 user_id 查列表或某个道具

    大神们一般是怎么做的,求指教.第一次用 pg,之前都是 mysql,有些地方不太懂

    1 条回复
    sagaxu
        1
    sagaxu  
       23 小时 37 分钟前
    跟 MySQL 不同的是,pgsql 里面,primary key = unique B-tree index + not null ,如果都是 not null ,你用复合主键还是唯一索引,性能上没有区别。

    题外话,用 user_id 来分区是糟糕的设计。

    All constraints on all children of the parent table are examined during constraint exclusion, so large numbers of children are likely to increase query planning time considerably. So the legacy inheritance based partitioning will work well with up to perhaps a hundred child tables; don't try to use many thousands of children.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2436 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:42 · PVG 18:42 · LAX 03:42 · JFK 06:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.