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)
11221122CheckMaxObjectId (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 ) ;
11291129tup -> t_data -> t_infomask &= ~(HEAP_XACT_MASK );
11301130tup -> t_data -> t_infomask |=HEAP_XMAX_INVALID ;
11311131tup -> t_tableOid = relation -> rd_id ;
@@ -1270,7 +1270,7 @@ heap_delete(Relation relation, ItemPointer tid,
12701270}
12711271else if (result == HeapTupleBeingUpdated )
12721272{
1273- TransactionId xwait = tp .t_data -> t_xmax ;
1273+ TransactionId xwait = HeapTupleHeaderGetXmax ( tp .t_data ) ;
12741274
12751275/* sleep until concurrent transaction ends */
12761276LockBuffer (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 ))
12891289gotol1 ;
12901290if (!(tp .t_data -> t_infomask & HEAP_XMAX_COMMITTED ))
12911291{
@@ -1309,10 +1309,10 @@ heap_delete(Relation relation, ItemPointer tid,
13091309
13101310START_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 ;
13141312tp .t_data -> t_infomask &= ~(HEAP_XMAX_COMMITTED |
13151313HEAP_XMAX_INVALID |HEAP_MARKED_FOR_UPDATE );
1314+ HeapTupleHeaderSetXmax (tp .t_data ,GetCurrentTransactionId ());
1315+ HeapTupleHeaderSetCmax (tp .t_data ,cid );
13161316/* XLOG stuff */
13171317{
13181318xl_heap_delete xlrec ;
@@ -1461,7 +1461,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
14611461}
14621462else if (result == HeapTupleBeingUpdated )
14631463{
1464- TransactionId xwait = oldtup .t_data -> t_xmax ;
1464+ TransactionId xwait = HeapTupleHeaderGetXmax ( oldtup .t_data ) ;
14651465
14661466/* sleep untill concurrent transaction ends */
14671467LockBuffer (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 ))
14801480gotol2 ;
14811481if (!(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 */
15021502newtup -> 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 ));
15061503newtup -> t_data -> t_infomask &= ~(HEAP_XACT_MASK );
15071504newtup -> 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 ;
15391539XactPushRollback (_heap_unlock_tuple , (void * )& _locked_tuple_ );
15401540
1541- TransactionIdStore (GetCurrentTransactionId (),
1542- & (oldtup .t_data -> t_xmax ));
1543- oldtup .t_data -> t_cmax = cid ;
15441541oldtup .t_data -> t_infomask &= ~(HEAP_XMAX_COMMITTED |
15451542HEAP_XMAX_INVALID |
15461543HEAP_MARKED_FOR_UPDATE );
15471544oldtup .t_data -> t_infomask |=HEAP_XMAX_UNLOGGED ;
1545+ HeapTupleHeaderSetXmax (oldtup .t_data ,GetCurrentTransactionId ());
1546+ HeapTupleHeaderSetCmax (oldtup .t_data ,cid );
15481547already_marked = true;
15491548LockBuffer (buffer ,BUFFER_LOCK_UNLOCK );
15501549
@@ -1630,12 +1629,11 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
16301629}
16311630else
16321631{
1633- TransactionIdStore (GetCurrentTransactionId (),
1634- & (oldtup .t_data -> t_xmax ));
1635- oldtup .t_data -> t_cmax = cid ;
16361632oldtup .t_data -> t_infomask &= ~(HEAP_XMAX_COMMITTED |
16371633HEAP_XMAX_INVALID |
16381634HEAP_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}
17601758else if (result == HeapTupleBeingUpdated )
17611759{
1762- TransactionId xwait = tuple -> t_data -> t_xmax ;
1760+ TransactionId xwait = HeapTupleHeaderGetXmax ( tuple -> t_data ) ;
17631761
17641762/* sleep untill concurrent transaction ends */
17651763LockBuffer (* 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 ))
17781776gotol3 ;
17791777if (!(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 ;
18071803tuple -> t_data -> t_infomask &= ~(HEAP_XMAX_COMMITTED |HEAP_XMAX_INVALID );
18081804tuple -> t_data -> t_infomask |=HEAP_MARKED_FOR_UPDATE ;
1805+ HeapTupleHeaderSetXmax (tuple -> t_data ,GetCurrentTransactionId ());
1806+ HeapTupleHeaderSetCmax (tuple -> t_data ,cid );
18091807
18101808LockBuffer (* buffer ,BUFFER_LOCK_UNLOCK );
18111809
@@ -1981,15 +1979,17 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
19811979if (move )/* remember xmin & xmax */
19821980{
19831981TransactionId xmax ;
1982+ TransactionId xmin ;
19841983
19851984if (newtup -> t_data -> t_infomask & HEAP_XMAX_INVALID ||
19861985newtup -> t_data -> t_infomask & HEAP_MARKED_FOR_UPDATE )
19871986xmax = InvalidTransactionId ;
19881987else
1989- xmax = newtup -> t_data -> t_xmax ;
1988+ xmax = HeapTupleHeaderGetXmax (newtup -> t_data );
1989+ xmin = HeapTupleHeaderGetXmin (newtup -> t_data );
19901990memcpy ((char * )& xlhdr + hsize ,& xmax ,sizeof (TransactionId ));
19911991memcpy ((char * )& xlhdr + hsize + sizeof (TransactionId ),
1992- & ( newtup -> t_data -> t_xmin ) ,sizeof (TransactionId ));
1992+ & xmin ,sizeof (TransactionId ));
19931993hsize += 2 * sizeof (TransactionId );
19941994}
19951995rdata [2 ].buffer = newbuf ;
@@ -2126,10 +2126,10 @@ heap_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
21262126
21272127if (redo )
21282128{
2129- htup -> t_xmax = record -> xl_xid ;
2130- htup -> t_cmax = FirstCommandId ;
21312129htup -> t_infomask &= ~(HEAP_XMAX_COMMITTED |
21322130HEAP_XMAX_INVALID |HEAP_MARKED_FOR_UPDATE );
2131+ HeapTupleHeaderSetXmax (htup ,record -> xl_xid );
2132+ HeapTupleHeaderSetCmax (htup ,FirstCommandId );
21332133PageSetLSN (page ,lsn );
21342134PageSetSUI (page ,ThisStartUpID );
21352135UnlockAndWriteBuffer (buffer );
@@ -2201,11 +2201,11 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
22012201htup -> t_oid = xlhdr .t_oid ;
22022202htup -> t_natts = xlhdr .t_natts ;
22032203htup -> 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 ;
22082204htup -> 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
22102210offnum = PageAddItem (page , (Item )htup ,newlen ,offnum ,
22112211LP_USED |OverwritePageMode );
@@ -2286,17 +2286,17 @@ heap_xlog_update(bool redo, XLogRecPtr lsn, XLogRecord *record, bool move)
22862286{
22872287if (move )
22882288{
2289- TransactionIdStore (record -> xl_xid , (TransactionId * )& (htup -> t_cmin ));
22902289htup -> t_infomask &=
22912290~(HEAP_XMIN_COMMITTED |HEAP_XMIN_INVALID |HEAP_MOVED_IN );
22922291htup -> t_infomask |=HEAP_MOVED_OFF ;
2292+ HeapTupleHeaderSetXvac (htup ,record -> xl_xid );
22932293}
22942294else
22952295{
2296- htup -> t_xmax = record -> xl_xid ;
2297- htup -> t_cmax = FirstCommandId ;
22982296htup -> t_infomask &= ~(HEAP_XMAX_COMMITTED |
22992297HEAP_XMAX_INVALID |HEAP_MARKED_FOR_UPDATE );
2298+ HeapTupleHeaderSetXmax (htup ,record -> xl_xid );
2299+ HeapTupleHeaderSetCmax (htup ,FirstCommandId );
23002300}
23012301if (samepage )
23022302gotonewsame ;
@@ -2372,26 +2372,27 @@ newsame:;
23722372htup -> t_hoff = xlhdr .t_hoff ;
23732373if (move )
23742374{
2375+ TransactionId xmax ;
2376+ TransactionId xmin ;
2377+
23752378hsize = 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 ));
23832381htup -> t_infomask = xlhdr .mask ;
23842382htup -> t_infomask &= ~(HEAP_XMIN_COMMITTED |
23852383HEAP_XMIN_INVALID |HEAP_MOVED_OFF );
23862384htup -> t_infomask |=HEAP_MOVED_IN ;
2385+ HeapTupleHeaderSetXmin (htup ,xmin );
2386+ HeapTupleHeaderSetXmax (htup ,xmax );
2387+ HeapTupleHeaderSetXvac (htup ,record -> xl_xid );
23872388}
23882389else
23892390{
2390- htup -> t_xmin = record -> xl_xid ;
2391- htup -> t_cmin = FirstCommandId ;
2392- htup -> t_xmax = InvalidTransactionId ;
2393- htup -> t_cmax = FirstCommandId ;
23942391htup -> 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
23972398offnum = PageAddItem (page , (Item )htup ,newlen ,offnum ,
@@ -2445,7 +2446,7 @@ _heap_unlock_tuple(void *data)
24452446
24462447htup = (HeapTupleHeader )PageGetItem (page ,lp );
24472448
2448- if (!TransactionIdEquals (htup -> t_xmax ,GetCurrentTransactionId ()))
2449+ if (!TransactionIdEquals (HeapTupleHeaderGetXmax ( htup ) ,GetCurrentTransactionId ()))
24492450elog (PANIC ,"_heap_unlock_tuple: invalid xmax in rollback" );
24502451htup -> t_infomask &= ~HEAP_XMAX_UNLOGGED ;
24512452htup -> t_infomask |=HEAP_XMAX_INVALID ;