Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit97bfffe

Browse files
committed
This patch, which is built upon the "HeapTupleHeader accessor macros"
patch from 2002-06-10, is supposed to reduce the heap tuple header sizeby four bytes on most architectures. Of course it changes the on-disktuple format and therefore requires initdb.This overlays cmin/cmax/xmax fields into only two fields.Manfred Koizar
1 parent8661039 commit97bfffe

File tree

3 files changed

+90
-31
lines changed

3 files changed

+90
-31
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.139 2002/06/20 20:29:24 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.140 2002/07/02 05:46:14 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -2204,7 +2204,7 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
22042204
htup->t_infomask=HEAP_XMAX_INVALID |xlhdr.mask;
22052205
HeapTupleHeaderSetXmin(htup,record->xl_xid);
22062206
HeapTupleHeaderSetCmin(htup,FirstCommandId);
2207-
HeapTupleHeaderSetXmax(htup,InvalidTransactionId);
2207+
HeapTupleHeaderSetXmaxInvalid(htup);
22082208
HeapTupleHeaderSetCmax(htup,FirstCommandId);
22092209

22102210
offnum=PageAddItem(page, (Item)htup,newlen,offnum,

‎src/include/access/htup.h

Lines changed: 86 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: htup.h,v 1.54 2002/06/20 20:29:43 momjian Exp $
10+
* $Id: htup.h,v 1.55 2002/07/02 05:46:14 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -57,15 +57,24 @@
5757
* Also note that we omit the nulls bitmap if t_infomask shows that there
5858
* are no nulls in the tuple.
5959
*/
60+
/*
61+
** We store five "virtual" fields Xmin, Cmin, Xmax, Cmax, and Xvac
62+
** in three physical fields t_xmin, t_cid, t_xmax:
63+
** CommandId Cmin;insert CID stamp
64+
** CommandId Cmax;delete CommandId stamp
65+
** TransactionId Xmin;insert XID stamp
66+
** TransactionId Xmax;delete XID stamp
67+
** TransactionId Xvac;used by VACCUUM
68+
**
69+
** This assumes, that a CommandId can be stored in a TransactionId.
70+
*/
6071
typedefstructHeapTupleHeaderData
6172
{
6273
Oidt_oid;/* OID of this tuple -- 4 bytes */
6374

64-
CommandIdt_cmin;/* insert CID stamp -- 4 bytes each */
65-
CommandIdt_cmax;/* delete CommandId stamp */
66-
67-
TransactionIdt_xmin;/* insert XID stamp -- 4 bytes each */
68-
TransactionIdt_xmax;/* delete XID stamp */
75+
TransactionIdt_xmin;/* Xmin -- 4 bytes each */
76+
TransactionIdt_cid;/* Cmin, Cmax, Xvac */
77+
TransactionIdt_xmax;/* Xmax, Cmax */
6978

7079
ItemPointerDatat_ctid;/* current TID of this or newer tuple */
7180

@@ -75,7 +84,7 @@ typedef struct HeapTupleHeaderData
7584

7685
uint8t_hoff;/* sizeof header incl. bitmap, padding */
7786

78-
/* ^ -31 bytes - ^ */
87+
/* ^ -27 bytes - ^ */
7988

8089
bits8t_bits[1];/* bitmap of NULLs -- VARIABLE LENGTH */
8190

@@ -96,6 +105,8 @@ typedef HeapTupleHeaderData *HeapTupleHeader;
96105
* attribute(s) */
97106
#defineHEAP_HASEXTENDED0x000C/* the two above combined */
98107

108+
#defineHEAP_XMIN_IS_XMAX0x0040/* created and deleted in the */
109+
/* same transaction */
99110
#defineHEAP_XMAX_UNLOGGED0x0080/* to lock tuple for update */
100111
/* without logging */
101112
#defineHEAP_XMIN_COMMITTED0x0100/* t_xmin committed */
@@ -108,6 +119,7 @@ typedef HeapTupleHeaderData *HeapTupleHeader;
108119
* vacuum */
109120
#defineHEAP_MOVED_IN0x8000/* moved from another place by
110121
* vacuum */
122+
#defineHEAP_MOVED (HEAP_MOVED_OFF | HEAP_MOVED_IN)
111123

112124
#defineHEAP_XACT_MASK0xFFF0/* visibility-related bits */
113125

@@ -116,53 +128,100 @@ typedef HeapTupleHeaderData *HeapTupleHeader;
116128
/* HeapTupleHeader accessor macros */
117129

118130
#defineHeapTupleHeaderGetXmin(tup) \
119-
((tup)->t_xmin)
131+
( \
132+
(tup)->t_xmin \
133+
)
120134

121135
#defineHeapTupleHeaderGetXmax(tup) \
122-
((tup)->t_xmax)
136+
( \
137+
((tup)->t_infomask & HEAP_XMIN_IS_XMAX) ? \
138+
(tup)->t_xmin \
139+
: \
140+
(tup)->t_xmax \
141+
)
123142

124-
/* no AssertMacro, because this is read as a system-defined attributealso*/
143+
/* no AssertMacro, because this is read as a system-defined attribute */
125144
#defineHeapTupleHeaderGetCmin(tup) \
126145
( \
127-
(tup)->t_cmin \
146+
((tup)->t_infomask & HEAP_MOVED) ? \
147+
FirstCommandId \
148+
: \
149+
( \
150+
((tup)->t_infomask & (HEAP_XMIN_IS_XMAX | HEAP_XMAX_INVALID)) ? \
151+
(CommandId) (tup)->t_cid \
152+
: \
153+
FirstCommandId \
154+
) \
128155
)
129156

130157
#defineHeapTupleHeaderGetCmax(tup) \
131-
((tup)->t_cmax)
158+
( \
159+
((tup)->t_infomask & HEAP_MOVED) ? \
160+
FirstCommandId \
161+
: \
162+
( \
163+
((tup)->t_infomask & (HEAP_XMIN_IS_XMAX | HEAP_XMAX_INVALID)) ? \
164+
(CommandId) (tup)->t_xmax \
165+
: \
166+
(CommandId) (tup)->t_cid \
167+
) \
168+
)
132169

133170
#defineHeapTupleHeaderGetXvac(tup) \
134171
( \
135-
AssertMacro((tup)->t_infomask &(HEAP_MOVED_IN | HEAP_MOVED_OFF)), \
136-
(TransactionId) (tup)->t_cmin \
172+
AssertMacro((tup)->t_infomask &HEAP_MOVED), \
173+
(tup)->t_cid \
137174
)
138175

139176

140177
#defineHeapTupleHeaderSetXmin(tup,xid) \
141-
(TransactionIdStore((xid), &(tup)->t_xmin))
178+
( \
179+
TransactionIdStore((xid), &(tup)->t_xmin) \
180+
)
142181

143182
#defineHeapTupleHeaderSetXminInvalid(tup) \
144-
(StoreInvalidTransactionId(&(tup)->t_xmin))
183+
do { \
184+
(tup)->t_infomask &= ~HEAP_XMIN_IS_XMAX; \
185+
StoreInvalidTransactionId(&(tup)->t_xmin); \
186+
} while (0)
145187

146188
#defineHeapTupleHeaderSetXmax(tup,xid) \
147-
(TransactionIdStore((xid), &(tup)->t_xmax))
189+
do { \
190+
if (TransactionIdEquals((tup)->t_xmin, (xid))) \
191+
(tup)->t_infomask |= HEAP_XMIN_IS_XMAX; \
192+
else \
193+
{ \
194+
(tup)->t_infomask &= ~HEAP_XMIN_IS_XMAX; \
195+
TransactionIdStore((xid), &(tup)->t_xmax); \
196+
} \
197+
} while (0)
148198

149199
#defineHeapTupleHeaderSetXmaxInvalid(tup) \
150-
(StoreInvalidTransactionId(&(tup)->t_xmax))
200+
do { \
201+
(tup)->t_infomask &= ~HEAP_XMIN_IS_XMAX; \
202+
StoreInvalidTransactionId(&(tup)->t_xmax); \
203+
} while (0)
151204

152205
#defineHeapTupleHeaderSetCmin(tup,cid) \
153-
( \
154-
AssertMacro(!((tup)->t_infomask &(HEAP_MOVED_IN | HEAP_MOVED_OFF))), \
155-
(tup)->t_cmin =(cid) \
156-
)
206+
do { \
207+
Assert(!((tup)->t_infomask &HEAP_MOVED)); \
208+
TransactionIdStore((TransactionId)(cid), &(tup)->t_cid); \
209+
} while (0)
157210

158211
#defineHeapTupleHeaderSetCmax(tup,cid) \
159-
((tup)->t_cmax = (cid))
212+
do { \
213+
Assert(!((tup)->t_infomask & HEAP_MOVED)); \
214+
if ((tup)->t_infomask & HEAP_XMIN_IS_XMAX) \
215+
TransactionIdStore((TransactionId) (cid), &(tup)->t_xmax); \
216+
else \
217+
TransactionIdStore((TransactionId) (cid), &(tup)->t_cid); \
218+
} while (0)
160219

161220
#defineHeapTupleHeaderSetXvac(tup,xid) \
162-
( \
163-
AssertMacro((tup)->t_infomask &(HEAP_MOVED_IN | HEAP_MOVED_OFF)), \
164-
TransactionIdStore((xid),(TransactionId *) &((tup)->t_cmin)) \
165-
)
221+
do { \
222+
Assert((tup)->t_infomask &HEAP_MOVED); \
223+
TransactionIdStore((xid),&(tup)->t_cid); \
224+
} while (0)
166225

167226

168227
/*

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $Id: catversion.h,v 1.136 2002/06/20 20:29:43 momjian Exp $
40+
* $Id: catversion.h,v 1.137 2002/07/02 05:46:14 momjian Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200206151
56+
#defineCATALOG_VERSION_NO200207021
5757

5858
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp