1

我知道 PostgreSQL 中的物理存储如下所示:

heap table:
<old_tuple, t_xmin, t_xmax>
<new_tuple, t_xmin, t_xmax>
index:
<old_index_value, old_RID>
<new_index_value, new_RID>

所以Index-Only Scan需要帮助Visibility Map

我的问题是:为什么我们不将t_xmin,也存储t_xmax在索引中?

喜欢:

index:
<old_index_value, old_RID, t_xmin, t_xmax>
<new_index_value, new_RID, t_xmin, t_xmax>
4

1 回答 1

3

开销比较大——t_xmin、t_xmax 总共有 8 个字节,未来可能会有 16 个字节。因此,如果 Postgres 将这些值存储到索引中,那么几乎所有数字索引都会大 2 (bigint) 倍或 2/3 倍 (int)。

今天这不是问题(可能),但 Postgres 开始时间是 80 年的一半,磁盘容量是个大问题。

第二个动机可能是代码的复杂性和确保数据的一致性(没有硬锁定)。Postgres 中的索引是数据访问加速器,而不是数据源。那么实现就更简单了。Ingres 是由非常聪明的教授和学生设计的,更健壮的不太复杂(但可能更慢)的设计是首选。

于 2021-02-13T11:09:13.393 回答