Skip to content

Commit 4d56701

Browse files
committed
Remove AMI_OVERRIDE tests from tqual.c routines; they aren't necessary
and just slow down normal operations (only fractionally, but a cycle saved is a cycle earned). Improve documentation of AMI_OVERRIDE behavior.
1 parent 29737d8 commit 4d56701

File tree

5 files changed

+41
-51
lines changed

5 files changed

+41
-51
lines changed

src/backend/access/transam/transam.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.50 2001/11/05 17:46:24 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.51 2002/05/25 20:00:11 tgl Exp $
1212
*
1313
* NOTES
1414
* This file contains the high level access-method interface to the
@@ -23,6 +23,18 @@
2323
#include "access/transam.h"
2424

2525

26+
/* ----------------
27+
* Flag indicating that we are bootstrapping.
28+
*
29+
* Transaction ID generation is disabled during bootstrap; we just use
30+
* BootstrapTransactionId. Also, the transaction ID status-check routines
31+
* are short-circuited; they claim that BootstrapTransactionId has already
32+
* committed, allowing tuples already inserted to be seen immediately.
33+
* ----------------
34+
*/
35+
bool AMI_OVERRIDE = false;
36+
37+
2638
static bool TransactionLogTest(TransactionId transactionId, XidStatus status);
2739
static void TransactionLogUpdate(TransactionId transactionId,
2840
XidStatus status);
@@ -160,7 +172,10 @@ bool /* true if given transaction committed */
160172
TransactionIdDidCommit(TransactionId transactionId)
161173
{
162174
if (AMI_OVERRIDE)
175+
{
176+
Assert(transactionId == BootstrapTransactionId);
163177
return true;
178+
}
164179

165180
return TransactionLogTest(transactionId, TRANSACTION_STATUS_COMMITTED);
166181
}
@@ -176,7 +191,10 @@ bool /* true if given transaction aborted */
176191
TransactionIdDidAbort(TransactionId transactionId)
177192
{
178193
if (AMI_OVERRIDE)
194+
{
195+
Assert(transactionId == BootstrapTransactionId);
179196
return false;
197+
}
180198

181199
return TransactionLogTest(transactionId, TRANSACTION_STATUS_ABORTED);
182200
}
@@ -193,7 +211,10 @@ bool
193211
TransactionIdIsInProgress(TransactionId transactionId)
194212
{
195213
if (AMI_OVERRIDE)
214+
{
215+
Assert(transactionId == BootstrapTransactionId);
196216
return false;
217+
}
197218

198219
return TransactionLogTest(transactionId, TRANSACTION_STATUS_IN_PROGRESS);
199220
}
@@ -215,9 +236,6 @@ TransactionIdIsInProgress(TransactionId transactionId)
215236
void
216237
TransactionIdCommit(TransactionId transactionId)
217238
{
218-
if (AMI_OVERRIDE)
219-
return;
220-
221239
TransactionLogUpdate(transactionId, TRANSACTION_STATUS_COMMITTED);
222240
}
223241

@@ -231,9 +249,6 @@ TransactionIdCommit(TransactionId transactionId)
231249
void
232250
TransactionIdAbort(TransactionId transactionId)
233251
{
234-
if (AMI_OVERRIDE)
235-
return;
236-
237252
TransactionLogUpdate(transactionId, TRANSACTION_STATUS_ABORTED);
238253
}
239254

src/backend/access/transam/varsup.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (c) 2000, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.48 2001/10/28 06:25:42 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.49 2002/05/25 20:00:11 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -93,13 +93,6 @@ ReadNewTransactionId(void)
9393
{
9494
TransactionId xid;
9595

96-
/*
97-
* During bootstrap initialization, we return the special bootstrap
98-
* transaction id.
99-
*/
100-
if (AMI_OVERRIDE)
101-
return BootstrapTransactionId;
102-
10396
LWLockAcquire(XidGenLock, LW_SHARED);
10497
xid = ShmemVariableCache->nextXid;
10598
LWLockRelease(XidGenLock);

src/backend/access/transam/xact.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.124 2002/05/22 21:40:55 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.125 2002/05/25 20:00:12 tgl Exp $
1212
*
1313
* NOTES
1414
* Transaction aborts can now occur two ways:
@@ -229,13 +229,6 @@ int CommitSiblings = 5; /* number of concurrent xacts needed to
229229
static void (*_RollbackFunc) (void *) = NULL;
230230
static void *_RollbackData = NULL;
231231

232-
/* ----------------
233-
* catalog creation transaction bootstrapping flag.
234-
* This should be eliminated and added to the transaction
235-
* state stuff. -cim 3/19/90
236-
* ----------------
237-
*/
238-
bool AMI_OVERRIDE = false;
239232

240233
/* ----------------------------------------------------------------
241234
* transaction state accessors
@@ -380,6 +373,11 @@ GetCurrentTransactionStartTimeUsec(int *msec)
380373

381374
/* --------------------------------
382375
* TransactionIdIsCurrentTransactionId
376+
*
377+
* During bootstrap, we cheat and say "it's not my transaction ID" even though
378+
* it is. Along with transam.c's cheat to say that the bootstrap XID is
379+
* already committed, this causes the tqual.c routines to see previously
380+
* inserted tuples as committed, which is what we need during bootstrap.
383381
* --------------------------------
384382
*/
385383
bool
@@ -388,7 +386,10 @@ TransactionIdIsCurrentTransactionId(TransactionId xid)
388386
TransactionState s = CurrentTransactionState;
389387

390388
if (AMI_OVERRIDE)
389+
{
390+
Assert(xid == BootstrapTransactionId);
391391
return false;
392+
}
392393

393394
return TransactionIdEquals(xid, s->transactionIdData);
394395
}
@@ -403,9 +404,6 @@ CommandIdIsCurrentCommandId(CommandId cid)
403404
{
404405
TransactionState s = CurrentTransactionState;
405406

406-
if (AMI_OVERRIDE)
407-
return false;
408-
409407
return (cid == s->commandId) ? true : false;
410408
}
411409

src/backend/utils/time/tqual.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Portions Copyright (c) 1994, Regents of the University of California
1717
*
1818
* IDENTIFICATION
19-
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.53 2002/05/24 18:57:56 tgl Exp $
19+
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.54 2002/05/25 20:00:12 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -202,9 +202,6 @@ HeapTupleSatisfiesItself(HeapTupleHeader tuple)
202202
bool
203203
HeapTupleSatisfiesNow(HeapTupleHeader tuple)
204204
{
205-
if (AMI_OVERRIDE)
206-
return true;
207-
208205
if (!(tuple->t_infomask & HEAP_XMIN_COMMITTED))
209206
{
210207
if (tuple->t_infomask & HEAP_XMIN_INVALID)
@@ -375,9 +372,6 @@ HeapTupleSatisfiesUpdate(HeapTuple htuple, CommandId curcid)
375372
{
376373
HeapTupleHeader tuple = htuple->t_data;
377374

378-
if (AMI_OVERRIDE)
379-
return HeapTupleMayBeUpdated;
380-
381375
if (!(tuple->t_infomask & HEAP_XMIN_COMMITTED))
382376
{
383377
if (tuple->t_infomask & HEAP_XMIN_INVALID)
@@ -509,9 +503,6 @@ HeapTupleSatisfiesDirty(HeapTupleHeader tuple)
509503
SnapshotDirty->xmin = SnapshotDirty->xmax = InvalidTransactionId;
510504
ItemPointerSetInvalid(&(SnapshotDirty->tid));
511505

512-
if (AMI_OVERRIDE)
513-
return true;
514-
515506
if (!(tuple->t_infomask & HEAP_XMIN_COMMITTED))
516507
{
517508
if (tuple->t_infomask & HEAP_XMIN_INVALID)
@@ -639,9 +630,6 @@ HeapTupleSatisfiesDirty(HeapTupleHeader tuple)
639630
bool
640631
HeapTupleSatisfiesSnapshot(HeapTupleHeader tuple, Snapshot snapshot)
641632
{
642-
if (AMI_OVERRIDE)
643-
return true;
644-
645633
/* XXX this is horribly ugly: */
646634
if (ReferentialIntegritySnapshotOverride)
647635
return HeapTupleSatisfiesNow(tuple);

src/include/access/transam.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: transam.h,v 1.44 2001/11/05 17:46:31 momjian Exp $
10+
* $Id: transam.h,v 1.45 2002/05/25 20:00:12 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -92,6 +92,13 @@ typedef VariableCacheData *VariableCache;
9292
* ----------------
9393
*/
9494

95+
/* in transam/transam.c */
96+
extern bool AMI_OVERRIDE;
97+
98+
/* in transam/varsup.c */
99+
extern VariableCache ShmemVariableCache;
100+
101+
95102
/*
96103
* prototypes for functions in transam/transam.c
97104
*/
@@ -111,15 +118,4 @@ extern TransactionId ReadNewTransactionId(void);
111118
extern Oid GetNewObjectId(void);
112119
extern void CheckMaxObjectId(Oid assigned_oid);
113120

114-
/* ----------------
115-
* global variable extern declarations
116-
* ----------------
117-
*/
118-
119-
/* in xact.c */
120-
extern bool AMI_OVERRIDE;
121-
122-
/* in varsup.c */
123-
extern VariableCache ShmemVariableCache;
124-
125121
#endif /* TRAMSAM_H */

0 commit comments

Comments
 (0)