postgreSQL 的 page

前端之家收集整理的这篇文章主要介绍了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;

原文链接:/postgresql/197158.html

猜你在找的Postgre SQL相关文章