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

Commit3c35fac

Browse files
committed
This patch wraps all accesses to t_xmin, t_cmin, t_xmax, and t_cmax in
HeapTupleHeaderData in setter and getter macros calledHeapTupleHeaderGetXmin, HeapTupleHeaderSetXmin etc.It also introduces a "virtual" field xvac by definingHeapTupleHeaderGetXvac and HeapTupleHeaderSetXvac. Xvac is used byVACUUM, in fact it is stored in t_cmin.Manfred Koizar
1 parent7882179 commit3c35fac

File tree

14 files changed

+312
-246
lines changed

14 files changed

+312
-246
lines changed

‎src/backend/access/common/heaptuple.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.75 2002/05/27 19:53:33 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.76 2002/06/15 19:54:23 momjian Exp $
1313
*
1414
* NOTES
1515
* The old interface functions have been converted to macros
@@ -439,16 +439,16 @@ heap_getsysattr(HeapTuple tup, int attnum, bool *isnull)
439439
result=ObjectIdGetDatum(tup->t_data->t_oid);
440440
break;
441441
caseMinTransactionIdAttributeNumber:
442-
result=TransactionIdGetDatum(tup->t_data->t_xmin);
442+
result=TransactionIdGetDatum(HeapTupleHeaderGetXmin(tup->t_data));
443443
break;
444444
caseMinCommandIdAttributeNumber:
445-
result=CommandIdGetDatum(tup->t_data->t_cmin);
445+
result=CommandIdGetDatum(HeapTupleHeaderGetCmin(tup->t_data));
446446
break;
447447
caseMaxTransactionIdAttributeNumber:
448-
result=TransactionIdGetDatum(tup->t_data->t_xmax);
448+
result=TransactionIdGetDatum(HeapTupleHeaderGetXmax(tup->t_data));
449449
break;
450450
caseMaxCommandIdAttributeNumber:
451-
result=CommandIdGetDatum(tup->t_data->t_cmax);
451+
result=CommandIdGetDatum(HeapTupleHeaderGetCmax(tup->t_data));
452452
break;
453453
caseTableOidAttributeNumber:
454454
result=ObjectIdGetDatum(tup->t_tableOid);

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

Lines changed: 48 additions & 47 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.137 2002/05/24 19:52:43 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.138 2002/06/15 19:54:23 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1122,10 +1122,10 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid)
11221122
CheckMaxObjectId(tup->t_data->t_oid);
11231123
}
11241124

1125-
TransactionIdStore(GetCurrentTransactionId(),&(tup->t_data->t_xmin));
1126-
tup->t_data->t_cmin=cid;
1127-
StoreInvalidTransactionId(&(tup->t_data->t_xmax));
1128-
tup->t_data->t_cmax=FirstCommandId;
1125+
HeapTupleHeaderSetXmin(tup->t_data,GetCurrentTransactionId());
1126+
HeapTupleHeaderSetCmin(tup->t_data,cid);
1127+
HeapTupleHeaderSetXmaxInvalid(tup->t_data);
1128+
HeapTupleHeaderSetCmax(tup->t_data,FirstCommandId);
11291129
tup->t_data->t_infomask &= ~(HEAP_XACT_MASK);
11301130
tup->t_data->t_infomask |=HEAP_XMAX_INVALID;
11311131
tup->t_tableOid=relation->rd_id;
@@ -1270,7 +1270,7 @@ heap_delete(Relation relation, ItemPointer tid,
12701270
}
12711271
elseif (result==HeapTupleBeingUpdated)
12721272
{
1273-
TransactionIdxwait=tp.t_data->t_xmax;
1273+
TransactionIdxwait=HeapTupleHeaderGetXmax(tp.t_data);
12741274

12751275
/* sleep until concurrent transaction ends */
12761276
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
@@ -1285,7 +1285,7 @@ heap_delete(Relation relation, ItemPointer tid,
12851285
* update then some other xaction could update this tuple before
12861286
* we got to this point.
12871287
*/
1288-
if (!TransactionIdEquals(tp.t_data->t_xmax,xwait))
1288+
if (!TransactionIdEquals(HeapTupleHeaderGetXmax(tp.t_data),xwait))
12891289
gotol1;
12901290
if (!(tp.t_data->t_infomask&HEAP_XMAX_COMMITTED))
12911291
{
@@ -1309,10 +1309,10 @@ heap_delete(Relation relation, ItemPointer tid,
13091309

13101310
START_CRIT_SECTION();
13111311
/* store transaction information of xact deleting the tuple */
1312-
TransactionIdStore(GetCurrentTransactionId(),&(tp.t_data->t_xmax));
1313-
tp.t_data->t_cmax=cid;
13141312
tp.t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED |
13151313
HEAP_XMAX_INVALID |HEAP_MARKED_FOR_UPDATE);
1314+
HeapTupleHeaderSetXmax(tp.t_data,GetCurrentTransactionId());
1315+
HeapTupleHeaderSetCmax(tp.t_data,cid);
13161316
/* XLOG stuff */
13171317
{
13181318
xl_heap_deletexlrec;
@@ -1461,7 +1461,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
14611461
}
14621462
elseif (result==HeapTupleBeingUpdated)
14631463
{
1464-
TransactionIdxwait=oldtup.t_data->t_xmax;
1464+
TransactionIdxwait=HeapTupleHeaderGetXmax(oldtup.t_data);
14651465

14661466
/* sleep untill concurrent transaction ends */
14671467
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
@@ -1476,7 +1476,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
14761476
* update then some other xaction could update this tuple before
14771477
* we got to this point.
14781478
*/
1479-
if (!TransactionIdEquals(oldtup.t_data->t_xmax,xwait))
1479+
if (!TransactionIdEquals(HeapTupleHeaderGetXmax(oldtup.t_data),xwait))
14801480
gotol2;
14811481
if (!(oldtup.t_data->t_infomask&HEAP_XMAX_COMMITTED))
14821482
{
@@ -1500,11 +1500,11 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
15001500

15011501
/* Fill in OID and transaction status data for newtup */
15021502
newtup->t_data->t_oid=oldtup.t_data->t_oid;
1503-
TransactionIdStore(GetCurrentTransactionId(),&(newtup->t_data->t_xmin));
1504-
newtup->t_data->t_cmin=cid;
1505-
StoreInvalidTransactionId(&(newtup->t_data->t_xmax));
15061503
newtup->t_data->t_infomask &= ~(HEAP_XACT_MASK);
15071504
newtup->t_data->t_infomask |= (HEAP_XMAX_INVALID |HEAP_UPDATED);
1505+
HeapTupleHeaderSetXmin(newtup->t_data,GetCurrentTransactionId());
1506+
HeapTupleHeaderSetCmin(newtup->t_data,cid);
1507+
HeapTupleHeaderSetXmaxInvalid(newtup->t_data);
15081508

15091509
/*
15101510
* If the toaster needs to be activated, OR if the new tuple will not
@@ -1538,13 +1538,12 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
15381538
_locked_tuple_.tid=oldtup.t_self;
15391539
XactPushRollback(_heap_unlock_tuple, (void*)&_locked_tuple_);
15401540

1541-
TransactionIdStore(GetCurrentTransactionId(),
1542-
&(oldtup.t_data->t_xmax));
1543-
oldtup.t_data->t_cmax=cid;
15441541
oldtup.t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED |
15451542
HEAP_XMAX_INVALID |
15461543
HEAP_MARKED_FOR_UPDATE);
15471544
oldtup.t_data->t_infomask |=HEAP_XMAX_UNLOGGED;
1545+
HeapTupleHeaderSetXmax(oldtup.t_data,GetCurrentTransactionId());
1546+
HeapTupleHeaderSetCmax(oldtup.t_data,cid);
15481547
already_marked= true;
15491548
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
15501549

@@ -1630,12 +1629,11 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
16301629
}
16311630
else
16321631
{
1633-
TransactionIdStore(GetCurrentTransactionId(),
1634-
&(oldtup.t_data->t_xmax));
1635-
oldtup.t_data->t_cmax=cid;
16361632
oldtup.t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED |
16371633
HEAP_XMAX_INVALID |
16381634
HEAP_MARKED_FOR_UPDATE);
1635+
HeapTupleHeaderSetXmax(oldtup.t_data,GetCurrentTransactionId());
1636+
HeapTupleHeaderSetCmax(oldtup.t_data,cid);
16391637
}
16401638

16411639
/* record address of new tuple in t_ctid of old one */
@@ -1759,7 +1757,7 @@ heap_mark4update(Relation relation, HeapTuple tuple, Buffer *buffer,
17591757
}
17601758
elseif (result==HeapTupleBeingUpdated)
17611759
{
1762-
TransactionIdxwait=tuple->t_data->t_xmax;
1760+
TransactionIdxwait=HeapTupleHeaderGetXmax(tuple->t_data);
17631761

17641762
/* sleep untill concurrent transaction ends */
17651763
LockBuffer(*buffer,BUFFER_LOCK_UNLOCK);
@@ -1774,7 +1772,7 @@ heap_mark4update(Relation relation, HeapTuple tuple, Buffer *buffer,
17741772
* update then some other xaction could update this tuple before
17751773
* we got to this point.
17761774
*/
1777-
if (!TransactionIdEquals(tuple->t_data->t_xmax,xwait))
1775+
if (!TransactionIdEquals(HeapTupleHeaderGetXmax(tuple->t_data),xwait))
17781776
gotol3;
17791777
if (!(tuple->t_data->t_infomask&HEAP_XMAX_COMMITTED))
17801778
{
@@ -1802,10 +1800,10 @@ heap_mark4update(Relation relation, HeapTuple tuple, Buffer *buffer,
18021800
((PageHeader)BufferGetPage(*buffer))->pd_sui=ThisStartUpID;
18031801

18041802
/* store transaction information of xact marking the tuple */
1805-
TransactionIdStore(GetCurrentTransactionId(),&(tuple->t_data->t_xmax));
1806-
tuple->t_data->t_cmax=cid;
18071803
tuple->t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED |HEAP_XMAX_INVALID);
18081804
tuple->t_data->t_infomask |=HEAP_MARKED_FOR_UPDATE;
1805+
HeapTupleHeaderSetXmax(tuple->t_data,GetCurrentTransactionId());
1806+
HeapTupleHeaderSetCmax(tuple->t_data,cid);
18091807

18101808
LockBuffer(*buffer,BUFFER_LOCK_UNLOCK);
18111809

@@ -1981,15 +1979,17 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
19811979
if (move)/* remember xmin & xmax */
19821980
{
19831981
TransactionIdxmax;
1982+
TransactionIdxmin;
19841983

19851984
if (newtup->t_data->t_infomask&HEAP_XMAX_INVALID||
19861985
newtup->t_data->t_infomask&HEAP_MARKED_FOR_UPDATE)
19871986
xmax=InvalidTransactionId;
19881987
else
1989-
xmax=newtup->t_data->t_xmax;
1988+
xmax=HeapTupleHeaderGetXmax(newtup->t_data);
1989+
xmin=HeapTupleHeaderGetXmin(newtup->t_data);
19901990
memcpy((char*)&xlhdr+hsize,&xmax,sizeof(TransactionId));
19911991
memcpy((char*)&xlhdr+hsize+sizeof(TransactionId),
1992-
&(newtup->t_data->t_xmin),sizeof(TransactionId));
1992+
&xmin,sizeof(TransactionId));
19931993
hsize+=2*sizeof(TransactionId);
19941994
}
19951995
rdata[2].buffer=newbuf;
@@ -2126,10 +2126,10 @@ heap_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
21262126

21272127
if (redo)
21282128
{
2129-
htup->t_xmax=record->xl_xid;
2130-
htup->t_cmax=FirstCommandId;
21312129
htup->t_infomask &= ~(HEAP_XMAX_COMMITTED |
21322130
HEAP_XMAX_INVALID |HEAP_MARKED_FOR_UPDATE);
2131+
HeapTupleHeaderSetXmax(htup,record->xl_xid);
2132+
HeapTupleHeaderSetCmax(htup,FirstCommandId);
21332133
PageSetLSN(page,lsn);
21342134
PageSetSUI(page,ThisStartUpID);
21352135
UnlockAndWriteBuffer(buffer);
@@ -2201,11 +2201,11 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
22012201
htup->t_oid=xlhdr.t_oid;
22022202
htup->t_natts=xlhdr.t_natts;
22032203
htup->t_hoff=xlhdr.t_hoff;
2204-
htup->t_xmin=record->xl_xid;
2205-
htup->t_cmin=FirstCommandId;
2206-
htup->t_xmax=InvalidTransactionId;
2207-
htup->t_cmax=FirstCommandId;
22082204
htup->t_infomask=HEAP_XMAX_INVALID |xlhdr.mask;
2205+
HeapTupleHeaderSetXmin(htup,record->xl_xid);
2206+
HeapTupleHeaderSetCmin(htup,FirstCommandId);
2207+
HeapTupleHeaderSetXmax(htup,InvalidTransactionId);
2208+
HeapTupleHeaderSetCmax(htup,FirstCommandId);
22092209

22102210
offnum=PageAddItem(page, (Item)htup,newlen,offnum,
22112211
LP_USED |OverwritePageMode);
@@ -2286,17 +2286,17 @@ heap_xlog_update(bool redo, XLogRecPtr lsn, XLogRecord *record, bool move)
22862286
{
22872287
if (move)
22882288
{
2289-
TransactionIdStore(record->xl_xid, (TransactionId*)&(htup->t_cmin));
22902289
htup->t_infomask &=
22912290
~(HEAP_XMIN_COMMITTED |HEAP_XMIN_INVALID |HEAP_MOVED_IN);
22922291
htup->t_infomask |=HEAP_MOVED_OFF;
2292+
HeapTupleHeaderSetXvac(htup,record->xl_xid);
22932293
}
22942294
else
22952295
{
2296-
htup->t_xmax=record->xl_xid;
2297-
htup->t_cmax=FirstCommandId;
22982296
htup->t_infomask &= ~(HEAP_XMAX_COMMITTED |
22992297
HEAP_XMAX_INVALID |HEAP_MARKED_FOR_UPDATE);
2298+
HeapTupleHeaderSetXmax(htup,record->xl_xid);
2299+
HeapTupleHeaderSetCmax(htup,FirstCommandId);
23002300
}
23012301
if (samepage)
23022302
gotonewsame;
@@ -2372,26 +2372,27 @@ newsame:;
23722372
htup->t_hoff=xlhdr.t_hoff;
23732373
if (move)
23742374
{
2375+
TransactionIdxmax;
2376+
TransactionIdxmin;
2377+
23752378
hsize=SizeOfHeapUpdate+SizeOfHeapHeader;
2376-
memcpy(&(htup->t_xmax),
2377-
(char*)xlrec+hsize,
2378-
sizeof(TransactionId));
2379-
memcpy(&(htup->t_xmin),
2380-
(char*)xlrec+hsize+sizeof(TransactionId),
2381-
sizeof(TransactionId));
2382-
TransactionIdStore(record->xl_xid, (TransactionId*)&(htup->t_cmin));
2379+
memcpy(&xmax, (char*)xlrec+hsize,sizeof(TransactionId));
2380+
memcpy(&xmin, (char*)xlrec+hsize+sizeof(TransactionId),sizeof(TransactionId));
23832381
htup->t_infomask=xlhdr.mask;
23842382
htup->t_infomask &= ~(HEAP_XMIN_COMMITTED |
23852383
HEAP_XMIN_INVALID |HEAP_MOVED_OFF);
23862384
htup->t_infomask |=HEAP_MOVED_IN;
2385+
HeapTupleHeaderSetXmin(htup,xmin);
2386+
HeapTupleHeaderSetXmax(htup,xmax);
2387+
HeapTupleHeaderSetXvac(htup,record->xl_xid);
23872388
}
23882389
else
23892390
{
2390-
htup->t_xmin=record->xl_xid;
2391-
htup->t_cmin=FirstCommandId;
2392-
htup->t_xmax=InvalidTransactionId;
2393-
htup->t_cmax=FirstCommandId;
23942391
htup->t_infomask=HEAP_XMAX_INVALID |xlhdr.mask;
2392+
HeapTupleHeaderSetXmin(htup,record->xl_xid);
2393+
HeapTupleHeaderSetCmin(htup,FirstCommandId);
2394+
HeapTupleHeaderSetXmaxInvalid(htup);
2395+
HeapTupleHeaderSetCmax(htup,FirstCommandId);
23952396
}
23962397

23972398
offnum=PageAddItem(page, (Item)htup,newlen,offnum,
@@ -2445,7 +2446,7 @@ _heap_unlock_tuple(void *data)
24452446

24462447
htup= (HeapTupleHeader)PageGetItem(page,lp);
24472448

2448-
if (!TransactionIdEquals(htup->t_xmax,GetCurrentTransactionId()))
2449+
if (!TransactionIdEquals(HeapTupleHeaderGetXmax(htup),GetCurrentTransactionId()))
24492450
elog(PANIC,"_heap_unlock_tuple: invalid xmax in rollback");
24502451
htup->t_infomask &= ~HEAP_XMAX_UNLOGGED;
24512452
htup->t_infomask |=HEAP_XMAX_INVALID;

‎src/backend/access/transam/xlogutils.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlogutils.c,v 1.23 2002/03/31 06:26:29 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlogutils.c,v 1.24 2002/06/15 19:54:23 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -73,7 +73,8 @@ XLogIsOwnerOfTuple(RelFileNode hnode, ItemPointer iptr,
7373
htup= (HeapTupleHeader)PageGetItem(page,lp);
7474

7575
Assert(PageGetSUI(page)==ThisStartUpID);
76-
if (!TransactionIdEquals(htup->t_xmin,xid)||htup->t_cmin!=cid)
76+
if (!TransactionIdEquals(HeapTupleHeaderGetXmin(htup),xid)||
77+
HeapTupleHeaderGetCmin(htup)!=cid)
7778
{
7879
UnlockAndReleaseBuffer(buffer);
7980
return (-1);
@@ -137,8 +138,8 @@ XLogIsValidTuple(RelFileNode hnode, ItemPointer iptr)
137138
{
138139
if (htup->t_infomask&HEAP_XMIN_INVALID||
139140
(htup->t_infomask&HEAP_MOVED_IN&&
140-
TransactionIdDidAbort((TransactionId)htup->t_cmin))||
141-
TransactionIdDidAbort(htup->t_xmin))
141+
TransactionIdDidAbort(HeapTupleHeaderGetXvac(htup)))||
142+
TransactionIdDidAbort(HeapTupleHeaderGetXmin(htup)))
142143
{
143144
UnlockAndReleaseBuffer(buffer);
144145
return (false);

‎src/backend/catalog/index.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.179 2002/05/21 22:05:53 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.180 2002/06/15 19:54:23 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1621,7 +1621,8 @@ IndexBuildHeapScan(Relation heapRelation,
16211621
* (Consider INSERT followed by CREATE INDEX within a
16221622
* transaction.)
16231623
*/
1624-
if (!TransactionIdIsCurrentTransactionId(heapTuple->t_data->t_xmin))
1624+
if (!TransactionIdIsCurrentTransactionId(
1625+
HeapTupleHeaderGetXmin(heapTuple->t_data)))
16251626
elog(ERROR,"IndexBuildHeapScan: concurrent insert in progress");
16261627
indexIt= true;
16271628
tupleIsAlive= true;
@@ -1635,7 +1636,8 @@ IndexBuildHeapScan(Relation heapRelation,
16351636
* (Consider DELETE followed by CREATE INDEX within a
16361637
* transaction.)
16371638
*/
1638-
if (!TransactionIdIsCurrentTransactionId(heapTuple->t_data->t_xmax))
1639+
if (!TransactionIdIsCurrentTransactionId(
1640+
HeapTupleHeaderGetXmax(heapTuple->t_data)))
16391641
elog(ERROR,"IndexBuildHeapScan: concurrent delete in progress");
16401642
indexIt= true;
16411643
tupleIsAlive= false;

‎src/backend/commands/sequence.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.79 2002/05/22 21:40:55 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.80 2002/06/15 19:54:23 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -249,10 +249,10 @@ DefineSequence(CreateSeqStmt *seq)
249249
itemId=PageGetItemId((Page)page,FirstOffsetNumber);
250250
item=PageGetItem((Page)page,itemId);
251251

252-
((HeapTupleHeader)item)->t_xmin=FrozenTransactionId;
252+
HeapTupleHeaderSetXmin((HeapTupleHeader)item,FrozenTransactionId);
253253
((HeapTupleHeader)item)->t_infomask |=HEAP_XMIN_COMMITTED;
254254

255-
tuple->t_data->t_xmin=FrozenTransactionId;
255+
HeapTupleHeaderSetXmin(tuple->t_data,FrozenTransactionId);
256256
tuple->t_data->t_infomask |=HEAP_XMIN_COMMITTED;
257257
}
258258

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp