htup.h

来自「PostgreSQL 8.2中增加了很多企业用户所需要的功能和性能上的提高,其开」· C头文件 代码 · 共 635 行 · 第 1/2 页

H
635
字号
#define MaxTupleSize	\	(BLCKSZ - MAXALIGN(sizeof(PageHeaderData) + MaxSpecialSpace))/* * MaxHeapTuplesPerPage is an upper bound on the number of tuples that can * fit on one heap page.  (Note that indexes could have more, because they * use a smaller tuple header.)  We arrive at the divisor because each tuple * must be maxaligned, and it must have an associated item pointer. */#define MaxHeapTuplesPerPage	\	((int) ((BLCKSZ - offsetof(PageHeaderData, pd_linp)) / \			(MAXALIGN(offsetof(HeapTupleHeaderData, t_bits)) + sizeof(ItemIdData))))/* * MaxAttrSize is a somewhat arbitrary upper limit on the declared size of * data fields of char(n) and similar types.  It need not have anything * directly to do with the *actual* upper limit of varlena values, which * is currently 1Gb (see struct varattrib in postgres.h).  I've set it * at 10Mb which seems like a reasonable number --- tgl 8/6/00. */#define MaxAttrSize		(10 * 1024 * 1024)/* * Attribute numbers for the system-defined attributes */#define SelfItemPointerAttributeNumber			(-1)#define ObjectIdAttributeNumber					(-2)#define MinTransactionIdAttributeNumber			(-3)#define MinCommandIdAttributeNumber				(-4)#define MaxTransactionIdAttributeNumber			(-5)#define MaxCommandIdAttributeNumber				(-6)#define TableOidAttributeNumber					(-7)#define FirstLowInvalidHeapAttributeNumber		(-8)/* * MinimalTuple is an alternate representation that is used for transient * tuples inside the executor, in places where transaction status information * is not required, the tuple rowtype is known, and shaving off a few bytes * is worthwhile because we need to store many tuples.	The representation * is chosen so that tuple access routines can work with either full or * minimal tuples via a HeapTupleData pointer structure.  The access routines * see no difference, except that they must not access the transaction status * or t_ctid fields because those aren't there. * * For the most part, MinimalTuples should be accessed via TupleTableSlot * routines.  These routines will prevent access to the "system columns" * and thereby prevent accidental use of the nonexistent fields. * * MinimalTupleData contains a length word, some padding, and fields matching * HeapTupleHeaderData beginning with t_natts.	The padding is chosen so that * offsetof(t_natts) is the same modulo MAXIMUM_ALIGNOF in both structs. * This makes data alignment rules equivalent in both cases. * * When a minimal tuple is accessed via a HeapTupleData pointer, t_data is * set to point MINIMAL_TUPLE_OFFSET bytes before the actual start of the * minimal tuple --- that is, where a full tuple matching the minimal tuple's * data would start.  This trick is what makes the structs seem equivalent. * * Note that t_hoff is computed the same as in a full tuple, hence it includes * the MINIMAL_TUPLE_OFFSET distance.  t_len does not include that, however. */#define MINIMAL_TUPLE_OFFSET \	((offsetof(HeapTupleHeaderData, t_natts) - sizeof(uint32)) / MAXIMUM_ALIGNOF * MAXIMUM_ALIGNOF)#define MINIMAL_TUPLE_PADDING \	((offsetof(HeapTupleHeaderData, t_natts) - sizeof(uint32)) % MAXIMUM_ALIGNOF)typedef struct MinimalTupleData{	uint32		t_len;			/* actual length of minimal tuple */	char		mt_padding[MINIMAL_TUPLE_PADDING];	/* Fields below here must match HeapTupleHeaderData! */	int16		t_natts;		/* number of attributes */	uint16		t_infomask;		/* various flag bits, see below */	uint8		t_hoff;			/* sizeof header incl. bitmap, padding */	/* ^ - 27 bytes - ^ */	bits8		t_bits[1];		/* bitmap of NULLs -- VARIABLE LENGTH */	/* MORE DATA FOLLOWS AT END OF STRUCT */} MinimalTupleData;typedef MinimalTupleData *MinimalTuple;/* * HeapTupleData is an in-memory data structure that points to a tuple. * * There are several ways in which this data structure is used: * * * Pointer to a tuple in a disk buffer: t_data points directly into the *	 buffer (which the code had better be holding a pin on, but this is not *	 reflected in HeapTupleData itself). * * * Pointer to nothing: t_data is NULL.  This is used as a failure indication *	 in some functions. * * * Part of a palloc'd tuple: the HeapTupleData itself and the tuple *	 form a single palloc'd chunk.  t_data points to the memory location *	 immediately following the HeapTupleData struct (at offset HEAPTUPLESIZE). *	 This is the output format of heap_form_tuple and related routines. * * * Separately allocated tuple: t_data points to a palloc'd chunk that *	 is not adjacent to the HeapTupleData.	(This case is deprecated since *	 it's difficult to tell apart from case #1.  It should be used only in *	 limited contexts where the code knows that case #1 will never apply.) * * * Separately allocated minimal tuple: t_data points MINIMAL_TUPLE_OFFSET *	 bytes before the start of a MinimalTuple.	As with the previous case, *	 this can't be told apart from case #1 by inspection; code setting up *	 or destroying this representation has to know what it's doing. * * t_len should always be valid, except in the pointer-to-nothing case. * t_self and t_tableOid should be valid if the HeapTupleData points to * a disk buffer, or if it represents a copy of a tuple on disk.  They * should be explicitly set invalid in manufactured tuples. */typedef struct HeapTupleData{	uint32		t_len;			/* length of *t_data */	ItemPointerData t_self;		/* SelfItemPointer */	Oid			t_tableOid;		/* table the tuple came from */	HeapTupleHeader t_data;		/* -> tuple header and data */} HeapTupleData;typedef HeapTupleData *HeapTuple;#define HEAPTUPLESIZE	MAXALIGN(sizeof(HeapTupleData))/* * GETSTRUCT - given a HeapTuple pointer, return address of the user data */#define GETSTRUCT(TUP) ((char *) ((TUP)->t_data) + (TUP)->t_data->t_hoff)/* * Accessor macros to be used with HeapTuple pointers. */#define HeapTupleIsValid(tuple) PointerIsValid(tuple)#define HeapTupleHasNulls(tuple) \		(((tuple)->t_data->t_infomask & HEAP_HASNULL) != 0)#define HeapTupleNoNulls(tuple) \		(!((tuple)->t_data->t_infomask & HEAP_HASNULL))#define HeapTupleHasVarWidth(tuple) \		(((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH) != 0)#define HeapTupleAllFixed(tuple) \		(!((tuple)->t_data->t_infomask & HEAP_HASVARWIDTH))#define HeapTupleHasExternal(tuple) \		(((tuple)->t_data->t_infomask & HEAP_HASEXTERNAL) != 0)#define HeapTupleHasCompressed(tuple) \		(((tuple)->t_data->t_infomask & HEAP_HASCOMPRESSED) != 0)#define HeapTupleHasExtended(tuple) \		(((tuple)->t_data->t_infomask & HEAP_HASEXTENDED) != 0)#define HeapTupleGetOid(tuple) \		HeapTupleHeaderGetOid((tuple)->t_data)#define HeapTupleSetOid(tuple, oid) \		HeapTupleHeaderSetOid((tuple)->t_data, (oid))/* * WAL record definitions for heapam.c's WAL operations * * XLOG allows to store some information in high 4 bits of log * record xl_info field.  We use 3 for opcode and one for init bit. */#define XLOG_HEAP_INSERT	0x00#define XLOG_HEAP_DELETE	0x10#define XLOG_HEAP_UPDATE	0x20#define XLOG_HEAP_MOVE		0x30#define XLOG_HEAP_CLEAN		0x40#define XLOG_HEAP_NEWPAGE	0x50#define XLOG_HEAP_LOCK		0x60#define XLOG_HEAP_INPLACE	0x70#define XLOG_HEAP_OPMASK	0x70/* * When we insert 1st item on new page in INSERT/UPDATE * we can (and we do) restore entire page in redo */#define XLOG_HEAP_INIT_PAGE 0x80/* * We ran out of opcodes, so heapam.c now has a second RmgrId.  These opcodes * are associated with RM_HEAP2_ID, but are not logically different from * the ones above associated with RM_HEAP_ID.  We apply XLOG_HEAP_OPMASK, * although currently XLOG_HEAP_INIT_PAGE is not used for any of these. */#define XLOG_HEAP2_FREEZE	0x00/* * All what we need to find changed tuple * * NB: on most machines, sizeof(xl_heaptid) will include some trailing pad * bytes for alignment.  We don't want to store the pad space in the XLOG, * so use SizeOfHeapTid for space calculations.  Similar comments apply for * the other xl_FOO structs. */typedef struct xl_heaptid{	RelFileNode node;	ItemPointerData tid;		/* changed tuple id */} xl_heaptid;#define SizeOfHeapTid		(offsetof(xl_heaptid, tid) + SizeOfIptrData)/* This is what we need to know about delete */typedef struct xl_heap_delete{	xl_heaptid	target;			/* deleted tuple id */} xl_heap_delete;#define SizeOfHeapDelete	(offsetof(xl_heap_delete, target) + SizeOfHeapTid)/* * We don't store the whole fixed part (HeapTupleHeaderData) of an inserted * or updated tuple in WAL; we can save a few bytes by reconstructing the * fields that are available elsewhere in the WAL record, or perhaps just * plain needn't be reconstructed.  These are the fields we must store. * NOTE: t_hoff could be recomputed, but we may as well store it because * it will come for free due to alignment considerations. */typedef struct xl_heap_header{	int16		t_natts;	uint16		t_infomask;	uint8		t_hoff;} xl_heap_header;#define SizeOfHeapHeader	(offsetof(xl_heap_header, t_hoff) + sizeof(uint8))/* This is what we need to know about insert */typedef struct xl_heap_insert{	xl_heaptid	target;			/* inserted tuple id */	/* xl_heap_header & TUPLE DATA FOLLOWS AT END OF STRUCT */} xl_heap_insert;#define SizeOfHeapInsert	(offsetof(xl_heap_insert, target) + SizeOfHeapTid)/* This is what we need to know about update|move */typedef struct xl_heap_update{	xl_heaptid	target;			/* deleted tuple id */	ItemPointerData newtid;		/* new inserted tuple id */	/* NEW TUPLE xl_heap_header (PLUS xmax & xmin IF MOVE OP) */	/* and TUPLE DATA FOLLOWS AT END OF STRUCT */} xl_heap_update;#define SizeOfHeapUpdate	(offsetof(xl_heap_update, newtid) + SizeOfIptrData)/* This is what we need to know about vacuum page cleanup */typedef struct xl_heap_clean{	RelFileNode node;	BlockNumber block;	/* UNUSED OFFSET NUMBERS FOLLOW AT THE END */} xl_heap_clean;#define SizeOfHeapClean (offsetof(xl_heap_clean, block) + sizeof(BlockNumber))/* This is for replacing a page's contents in toto *//* NB: this is used for indexes as well as heaps */typedef struct xl_heap_newpage{	RelFileNode node;	BlockNumber blkno;			/* location of new page */	/* entire page contents follow at end of record */} xl_heap_newpage;#define SizeOfHeapNewpage	(offsetof(xl_heap_newpage, blkno) + sizeof(BlockNumber))/* This is what we need to know about lock */typedef struct xl_heap_lock{	xl_heaptid	target;			/* locked tuple id */	TransactionId locking_xid;	/* might be a MultiXactId not xid */	bool		xid_is_mxact;	/* is it? */	bool		shared_lock;	/* shared or exclusive row lock? */} xl_heap_lock;#define SizeOfHeapLock	(offsetof(xl_heap_lock, shared_lock) + sizeof(bool))/* This is what we need to know about in-place update */typedef struct xl_heap_inplace{	xl_heaptid	target;			/* updated tuple id */	/* TUPLE DATA FOLLOWS AT END OF STRUCT */} xl_heap_inplace;#define SizeOfHeapInplace	(offsetof(xl_heap_inplace, target) + SizeOfHeapTid)/* This is what we need to know about tuple freezing during vacuum */typedef struct xl_heap_freeze{	RelFileNode node;	BlockNumber block;	TransactionId cutoff_xid;	/* TUPLE OFFSET NUMBERS FOLLOW AT THE END */} xl_heap_freeze;#define SizeOfHeapFreeze (offsetof(xl_heap_freeze, cutoff_xid) + sizeof(TransactionId))#endif   /* HTUP_H */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?