标题: PostgreSQL Free Space Map Principle from Source Code [打印本页] 作者: digoal 时间: 2011-02-22 19:53 标题: PostgreSQL Free Space Map Principle from Source Code 在说FSM之前,先回顾一个PostgreSQL的Limit
Limit Value
Maximum Database Size Unlimited
Maximum Table Size 32 TB
Maximum Row Size 1.6 TB
Maximum Field Size 1 GB
Maximum Rows per Table Unlimited
Maximum Columns per Table 250 – 1600 depending on column types
Maximum Indexes per Table Unlimited
fp_next_slot,决定一个PAGE中剩余空间的下一个搜索从哪里开始。这样做的目的是避免热块的产生,当有多个数据库进程请求插入同一个表时,有了fp_next_slot,数据可以插入到不同的PAGE中.同时,考虑到磁盘离散扫描将大大消耗磁盘的IO,所以在并发搜索PAGE的情况下fp_next_slot需要尽量返回靠的很近的PAGE,以满足操作系统级的 prefetching and batched writes.
看图,假设一个FSM PAGE可以存储4个PAGE的信息(真实情况下应该存储((BLCKSZ – headers) / 2, or ~4000 with default BLCKS)个PAGE的信息)
数字代表的是改级别下的FSM PAGE NUMBER,在通过SEARCH算法找到了FSM的LEAF NODE后,接下来就需要定位到表的PAGE了,表的PAGE实际上是通过FSM LEAF NODE的位置号算出来的,公式如下
y = n + (n / F + 1) + (n / F^2 + 1) + … + 1
where F is the fanout (4 in the above example). The first term n is the number of preceding leaf pages, the second term is the number of pages at level 1, and so forth.