postgreSQL 的 page

page的结构如下

* +----------------+---------------------------------+
* | PageHeaderData | linp1 linp2 linp3 ...     |
* +-----------+----+---------------------------------+
* | ... linpN |           |
* +-----------+--------------------------------------+
* |     ^ pd_lower         |
* |              |
* |    v pd_upper         |
* +-------------+------------------------------------+
* |    | tupleN ...        |
* +-------------+------------------+-----------------+
* |    ... tuple3 tuple2 tuple1 | "special space" |
* +--------------------------------+-----------------+
*          ^ pd_special

special space 只在索引的页面存在,普通的页面不存在这部分

typedef struct PageHeaderData
{
/* XXX LSN is member of *any* block, not only page-organized ones */
XLogRecPtr pd_lsn;    /* LSN: next byte after last byte of xlog
         * record for last change to this page */
uint16   pd_tli;    /* least significant bits of the TimeLineID
         * containing the LSN */
uint16   pd_flags;   /* flag bits, see below */
LocationIndex pd_lower;   /* offset to start of free space */
LocationIndex pd_upper;   /* offset to end of free space */
LocationIndex pd_special; /* offset to start of special space */
uint16   pd_pagesize_version;
TransactionId pd_prune_xid; /* oldest prunable XID, or zero if none */
ItemIdData pd_linp[1];   /* beginning of line pointer array */
} PageHeaderData;

 

typedef struct ItemIdData
{
unsigned lp_off:15,   /* offset to tuple (from start of page) */
     lp_flags:2,   /* state of item pointer, see below */
     lp_len:15;   /* byte length of tuple */
} ItemIdData;

里面的每个tuple如下:

typedef struct HeapTupleFields
{
TransactionId t_xmin;   /* inserting xact ID */
TransactionId t_xmax;   /* deleting or locking xact ID */

union
{
   CommandId t_cid;   /* inserting or deleting command ID, or both */
   TransactionId t_xvac; /* VACUUM FULL xact ID */
}    t_field3;
} HeapTupleFields;

typedef struct DatumTupleFields
{
int32   datum_len_;   /* varlena header (do not touch directly!) */

int32   datum_typmod; /* -1, or identifier of a record type */

Oid    datum_typeid; /* composite type OID, or RECORDOID */

/*
* Note: field ordering is chosen with thought that Oid might someday
* widen to 64 bits.
*/
} DatumTupleFields;

typedef struct HeapTupleHeaderData
{
union
{
   HeapTupleFields t_heap;
   DatumTupleFields t_datum;
}    t_choice;

ItemPointerData t_ctid;   /* current TID of this or newer tuple */

/* Fields below here must match MinimalTupleData! */

uint16   t_infomask2; /* number of attributes + various flags */

uint16   t_infomask;   /* various flag bits, see below */

uint8   t_hoff;    /* sizeof header incl. bitmap, padding */

/* ^ - 23 bytes - ^ */

bits8   t_bits[1];   /* bitmap of NULLs -- VARIABLE LENGTH */

/* MORE DATA FOLLOWS AT END OF STRUCT */
} HeapTupleHeaderData;

 

All index tuples start with IndexTupleData. If the HasNulls bit is set,
* this is followed by an IndexAttributeBitMapData. The index attribute
* values follow, beginning at a MAXALIGN boundary.

 

typedef struct IndexTupleData
{
ItemPointerData t_tid;   /* reference TID to heap tuple */

/* ---------------
* t_info is layed out in the following fashion:
*
* 15th (high) bit: has nulls
* 14th bit: has var-width attributes
* 13th bit: unused
* 12-0 bit: size of tuple
* ---------------
*/

unsigned short t_info;   /* various info about tuple */

} IndexTupleData;  

The overall structure of a heap tuple looks like:
*    fixed fields (HeapTupleHeaderData struct)
*    nulls bitmap (if HEAP_HASNULL is set in t_infomask)
*    alignment padding (as needed to make user data MAXALIGN'd)
*    object ID (if HEAP_HASOID is set in t_infomask)
*    user data fields

 

 

 

 

BTREE 的

typedef struct BTPageOpaqueData
{
BlockNumber btpo_prev;   /* left sibling, or P_NONE if leftmost */
BlockNumber btpo_next;   /* right sibling, or P_NONE if rightmost */
union
{
   uint32   level;   /* tree level --- zero for leaf pages */
   TransactionId xact;   /* next transaction ID, if deleted */
}    btpo;
uint16   btpo_flags;   /* flag bits, see below */
BTCycleId btpo_cycleid; /* vacuum cycle ID of latest split */
} BTPageOpaqueData;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值