PostgreSQL infomask/infomask2 学习记录

1. infomask

/* 元组包含NULL值字段 */
#define HEAP_HASNULL			0x0001	/* has null attribute(s) */
/* 元组包含可变长度的字段 */
#define HEAP_HASVARWIDTH		0x0002	/* has variable-width attribute(s)  */
/* 元组包含外部存储的字段 */
#define HEAP_HASEXTERNAL		0x0004	/* has external stored attribute(s) */

/* 由函数 heap_fill_tuple 赋值 */
/* 元组包含OID系统字段 */
#define HEAP_HASOID				0x0008	/* has an object-id field */

/* 由函数 heap_form_tuple, heap_form_minimal_tuple 赋值 */
/*
 * 元组的t_cid是组合command id
 * 这个标记,常用来标记本事务内的老记录。具体可参看函数:heap_delete, heap_update
 */
#define HEAP_COMBOCID			0x0020	/* t_cid is a combo cid */
/* 元组的xmax用来标志key-shared锁拥有者 */
#define HEAP_XMAX_KEYSHR_LOCK	0x0010	/* xmax is a key-shared locker */
/* 元组的xmax用来标志独占锁拥有者 */
#define HEAP_XMAX_EXCL_LOCK		0x0040	/* xmax is exclusive locker */
/* 元组的xmax如果有效,仅仅是个锁拥有者 */
#define HEAP_XMAX_LOCK_ONLY		0x0080	/* xmax, if valid, is only a locker */
 /* 元组的xmax用来标记共享锁拥有者,xmax is a shared locker */
#define HEAP_XMAX_SHR_LOCK	(HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_KEYSHR_LOCK)

#define HEAP_LOCK_MASK	(HEAP_XMAX_SHR_LOCK | HEAP_XMAX_EXCL_LOCK | \
						 HEAP_XMAX_KEYSHR_LOCK)

/* ------------------------------------------------------------------
 * 通过以下代码,可以看出以上关于锁的infomask,是在哪种情况下需要赋值的
 * ------------------------------------------------------------------ */

/*
 * Possible lock modes for a tuple.
 */
typedef enum LockTupleMode
{
	/* SELECT FOR KEY SHARE */
	LockTupleKeyShare,
	/* SELECT FOR SHARE */
	LockTupleShare,
	/* SELECT FOR NO KEY UPDATE, and UPDATEs that don't modify key columns */
	LockTupleNoKeyExclusive,
	/* SELECT FOR UPDATE, UPDATEs that modify key columns, and DELETE */
	LockTupleExclusive
} LockTupleMode;

new_infomask |= HEAP_XMAX_LOCK_ONLY;
switch (mode)
{
    case LockTupleKeyShare:
        new_xmax = add_to_xmax;
        new_infomask |= HEAP_XMAX_KEYSHR_LOCK;
        break;
    case LockTupleShare:
        new_xmax = add_to_xmax;
        new_infomask |= HEAP_XMAX_SHR_LOCK;
        break;
    case LockTupleNoKeyExclusive:
        new_xmax = add_to_xmax;
        new_infomask |= HEAP_XMAX_EXCL_LOCK;
        break;
    case LockTupleExclusive:
        new_xmax = add_to_xmax;
        new_infomask |= HEAP_XMAX_EXCL_LOCK;
        new_infomask2 |= HEAP_KEYS_UPDATED;
        break;
    default:
        new_xmax = InvalidTransactionId;	/* silence compiler */
        elog(ERROR, "invalid lock mode");
}
/* 元组的xmin是提交的 */
#define HEAP_XMIN_COMMITTED		0x0100	/* t_xmin committed */
/* 元组的xmin是无效的或回滚的 */
#define HEAP_XMIN_INVALID		0x0200	/* t_xmin invalid/aborted */
#define HEAP_XMIN_FROZEN		(HEAP_XMIN_COMMITTED|HEAP_XMIN_INVALID)
/* 元组的xmax是提交的 */
#define HEAP_XMAX_COMMITTED		0x0400	/* t_xmax committed */
/* 元组的xmax是无效的或回滚的 */
#define HEAP_XMAX_INVALID		0x0800	/* t_xmax invalid/aborted */

/*
 * 以上infomask,通常通过clog判定。
 */
/* 没找到是怎么赋值的 */
#define HEAP_XMAX_IS_MULTI		0x1000	/* t_xmax is a MultiXactId */
/* 元组是更新版本 */
#define HEAP_UPDATED			0x2000	/* this is UPDATEd version of row */

/* 该infomask的赋值,发生在函数:heap_update */
#define HEAP_MOVED_OFF			0x4000	/* moved to another place by pre-9.0
										 * VACUUM FULL; kept for binary
										 * upgrade support */
#define HEAP_MOVED_IN			0x8000	/* moved from another place by pre-9.0
										 * VACUUM FULL; kept for binary
										 * upgrade support */
#define HEAP_MOVED (HEAP_MOVED_OFF | HEAP_MOVED_IN)

/* 以上infomask,用于9.0以前的vacuum full操作 */
#define HEAP_XACT_MASK			0xFFF0	/* visibility-related bits */

2. infomask2

/* 用11个bits表示表的字段个数 */
#define HEAP_NATTS_MASK			0x07FF	/* 11 bits for number of attributes */

/* 赋值操作见函数 HeapTupleHeaderSetNatts */

#define MaxTupleAttributeNumber 1664	/* 8 * 208 */
#define MaxHeapAttributeNumber	1600	/* 8 * 200 */
/* bits 0x1800 are available */
#define HEAP_KEYS_UPDATED		0x2000	/* tuple was updated and key cols
										 * modified, or tuple deleted */
/* 赋值操作见函数 compute_new_xmax_infomask */

#define HEAP_HOT_UPDATED		0x4000	/* tuple was HOT-updated */
/* 赋值操作减函数:heap_update => HeapTupleSetHotUpdated => HeapTupleHeaderSetHotUpdated */

#define HEAP_ONLY_TUPLE			0x8000	/* this is heap-only tuple */
/* 赋值操作减函数:heap_update => HeapTupleSetHeapOnly => HeapTupleHeaderSetHeapOnly */

#define HEAP2_XACT_MASK			0xE000	/* visibility-related bits */

转载于:https://my.oschina.net/zaclu/blog/1796831

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值