PostgreSQL中的BlockIdData解释
本文是基于当前的PostgreSQL master分支进行介绍的,当前commitid为087d3d0583cf292146a7385746d1f5b53eeeaee6。
只要学习过PostgreSQL存储结构的同学,对于ctid一定不会陌生。ctid是PostgreSQL是对于物理tuple的标识符,不同对象存在相同的ctid。
ctid由两部分构成,page顺序值以及tuple顺序值,一般表示为,'(12, 33)'。page顺序值指的是page在所有segment中的顺序,是一个且连续的数值;tuple顺序值指的是在当前page页面中的顺序值。这两项就能够标识tuple了。
/*
* ItemPointer:
*
* This is a pointer to an item within a disk page of a known file
* (for example, a cross-link from an index to its parent table).
* ip_blkid tells us which block, ip_posid tells us which entry in
* the linp (ItemIdData) array we want.
*
* Note: because there is an item pointer in each tuple header and index
* tuple header on disk, it's very important not to waste space with
* structure padding bytes. The struct is designed to be six bytes long
* (it contains three int16 fields) but a few compilers will pad it to
* eight bytes unless coerced. We apply appropriate persuasion where
* possible. If your compiler can't be made to play along, you'll waste
* lots of space.
*/
typedef struct ItemPointerData
{
BlockIdData ip_blkid;
OffsetNumber ip_posid;
}
相关文章