Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 PostgreSQL 12 中设置了一个由哈希表分区的分区,它将有 256 个分区。我使用 uuid 作为表的主键。使用与哈希键相同的 uuid 列是否可以接受?
不仅可以接受,而且需要。
根据文档,11.6。唯一索引
“当为表定义唯一约束或主键时,PostgreSQL 会自动创建唯一索引。索引涵盖构成主键或唯一约束(多列索引,如果适用)的列,并且是强制执行约束。”
同样根据文档,5.11.2.3。限制,
以下限制适用于分区表:
“分区表的唯一约束必须包括所有分区键列。存在这个限制是因为 PostgreSQL 只能在每个分区中单独强制唯一性。”