mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Fix very old bug which made tuples changed/inserted by a commnd
visible to command itself (so we had multiple update of updated tuples, etc).
This commit is contained in:
		@@ -7,7 +7,7 @@
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 * IDENTIFICATION
 | 
			
		||||
 *    $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.12 1997/08/19 21:30:19 momjian Exp $
 | 
			
		||||
 *    $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.13 1997/08/29 09:02:11 vadim Exp $
 | 
			
		||||
 *	
 | 
			
		||||
 * NOTES
 | 
			
		||||
 *	Transaction aborts can now occur two ways:
 | 
			
		||||
@@ -377,6 +377,22 @@ GetCurrentCommandId()
 | 
			
		||||
    return s->commandId;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CommandId
 | 
			
		||||
GetScanCommandId()
 | 
			
		||||
{
 | 
			
		||||
    TransactionState s = CurrentTransactionState;
 | 
			
		||||
    
 | 
			
		||||
    /* ----------------
 | 
			
		||||
     *	if the transaction system is disabled, we return
 | 
			
		||||
     *  the special "disabled" command id.
 | 
			
		||||
     * ----------------
 | 
			
		||||
     */
 | 
			
		||||
    if (s->state == TRANS_DISABLED)
 | 
			
		||||
	return (CommandId) DisabledCommandId;
 | 
			
		||||
    
 | 
			
		||||
    return s->scanCommandId;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* --------------------------------
 | 
			
		||||
 *	GetCurrentTransactionStartTime
 | 
			
		||||
@@ -432,6 +448,18 @@ CommandIdIsCurrentCommandId(CommandId cid)
 | 
			
		||||
	(cid == s->commandId) ? true : false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool
 | 
			
		||||
CommandIdGEScanCommandId(CommandId cid)
 | 
			
		||||
{
 | 
			
		||||
    TransactionState s = CurrentTransactionState;
 | 
			
		||||
    
 | 
			
		||||
    if (AMI_OVERRIDE)
 | 
			
		||||
	return false;
 | 
			
		||||
    
 | 
			
		||||
    return 	
 | 
			
		||||
	(cid >= s->scanCommandId) ? true : false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* --------------------------------
 | 
			
		||||
 *	ClearCommandIdCounterOverflowFlag
 | 
			
		||||
@@ -458,11 +486,22 @@ CommandCounterIncrement()
 | 
			
		||||
	elog(WARN, "You may only have 65535 commands per transaction");
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    CurrentTransactionStateData.scanCommandId = 
 | 
			
		||||
    		CurrentTransactionStateData.commandId;
 | 
			
		||||
    
 | 
			
		||||
    /* make cache changes visible to me */
 | 
			
		||||
    AtCommit_Cache();
 | 
			
		||||
    AtStart_Cache();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void 
 | 
			
		||||
SetScanCommandId (CommandId savedId)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    CurrentTransactionStateData.scanCommandId = savedId;
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* ----------------------------------------------------------------
 | 
			
		||||
 *		        initialization stuff
 | 
			
		||||
 * ----------------------------------------------------------------
 | 
			
		||||
@@ -757,6 +796,7 @@ StartTransaction()
 | 
			
		||||
     * ----------------
 | 
			
		||||
     */
 | 
			
		||||
    s->commandId = 		FirstCommandId;
 | 
			
		||||
    s->scanCommandId = 		FirstCommandId;
 | 
			
		||||
    s->startTime = 		GetCurrentAbsoluteTime();
 | 
			
		||||
    
 | 
			
		||||
    /* ----------------
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 * IDENTIFICATION
 | 
			
		||||
 *    $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.3 1997/08/19 21:36:12 momjian Exp $
 | 
			
		||||
 *    $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.4 1997/08/29 09:04:54 vadim Exp $
 | 
			
		||||
 *
 | 
			
		||||
 *-------------------------------------------------------------------------
 | 
			
		||||
 */
 | 
			
		||||
@@ -580,6 +580,13 @@ HeapTupleSatisfiesItself(HeapTuple tuple)
 | 
			
		||||
 *	    (Xmax is not committed &&           the row was deleted by another transaction
 | 
			
		||||
 *           Xmax != my-transaction))))         that has not been committed
 | 
			
		||||
 *
 | 
			
		||||
 * XXX
 | 
			
		||||
 *	CommandId stuff didn't work properly if one used SQL-functions in 
 | 
			
		||||
 *	UPDATE/INSERT(fromSELECT)/DELETE scans: SQL-funcs call 
 | 
			
		||||
 *	CommandCounterIncrement and made tuples changed/inserted by
 | 
			
		||||
 *	current command visible to command itself (so we had multiple
 | 
			
		||||
 *	update of updated tuples, etc).		- vadim 08/29/97
 | 
			
		||||
 *	
 | 
			
		||||
 *	mao says 17 march 1993:  the tests in this routine are correct;
 | 
			
		||||
 *	if you think they're not, you're wrong, and you should think
 | 
			
		||||
 *	about it again.  i know, it happened to me.  we don't need to
 | 
			
		||||
@@ -615,13 +622,13 @@ HeapTupleSatisfiesNow(HeapTuple tuple)
 | 
			
		||||
    if (!AbsoluteTimeIsBackwardCompatiblyValid(tuple->t_tmin)) {
 | 
			
		||||
	
 | 
			
		||||
	if (TransactionIdIsCurrentTransactionId((TransactionId)tuple->t_xmin)
 | 
			
		||||
	    && CommandIdIsCurrentCommandId(tuple->t_cmin)) {
 | 
			
		||||
	    && CommandIdGEScanCommandId(tuple->t_cmin)) {
 | 
			
		||||
	    
 | 
			
		||||
	    return (false);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	if (TransactionIdIsCurrentTransactionId((TransactionId)tuple->t_xmin)
 | 
			
		||||
	    && !CommandIdIsCurrentCommandId(tuple->t_cmin)) {
 | 
			
		||||
	    && !CommandIdGEScanCommandId(tuple->t_cmin)) {
 | 
			
		||||
	    
 | 
			
		||||
	    if (!TransactionIdIsValid((TransactionId)tuple->t_xmax)) {
 | 
			
		||||
		return (true);
 | 
			
		||||
@@ -629,7 +636,7 @@ HeapTupleSatisfiesNow(HeapTuple tuple)
 | 
			
		||||
	    
 | 
			
		||||
	    Assert(TransactionIdIsCurrentTransactionId((TransactionId)tuple->t_xmax));
 | 
			
		||||
	    
 | 
			
		||||
	    if (CommandIdIsCurrentCommandId(tuple->t_cmax)) {
 | 
			
		||||
	    if (CommandIdGEScanCommandId(tuple->t_cmax)) {
 | 
			
		||||
		return (true);
 | 
			
		||||
	    }
 | 
			
		||||
	}
 | 
			
		||||
@@ -813,13 +820,13 @@ HeapTupleSatisfiesUpperUnboundedInternalTimeQual(HeapTuple tuple,
 | 
			
		||||
    if (!AbsoluteTimeIsBackwardCompatiblyValid(tuple->t_tmin)) {
 | 
			
		||||
	
 | 
			
		||||
	if (TransactionIdIsCurrentTransactionId((TransactionId)tuple->t_xmin) &&
 | 
			
		||||
	    CommandIdIsCurrentCommandId(tuple->t_cmin)) {
 | 
			
		||||
	    CommandIdGEScanCommandId(tuple->t_cmin)) {
 | 
			
		||||
	    
 | 
			
		||||
	    return (false);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	if (TransactionIdIsCurrentTransactionId((TransactionId)tuple->t_xmin) &&
 | 
			
		||||
	    !CommandIdIsCurrentCommandId(tuple->t_cmin)) {
 | 
			
		||||
	    !CommandIdGEScanCommandId(tuple->t_cmin)) {
 | 
			
		||||
	    
 | 
			
		||||
	    if (!TransactionIdIsValid((TransactionId)tuple->t_xmax)) {
 | 
			
		||||
		return (true);
 | 
			
		||||
@@ -827,7 +834,7 @@ HeapTupleSatisfiesUpperUnboundedInternalTimeQual(HeapTuple tuple,
 | 
			
		||||
	    
 | 
			
		||||
	    Assert(TransactionIdIsCurrentTransactionId((TransactionId)tuple->t_xmax));
 | 
			
		||||
	    
 | 
			
		||||
	    return ((bool) !CommandIdIsCurrentCommandId(tuple->t_cmax));
 | 
			
		||||
	    return ((bool) !CommandIdGEScanCommandId(tuple->t_cmax));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	if (!TransactionIdDidCommit((TransactionId)tuple->t_xmin)) {
 | 
			
		||||
@@ -849,7 +856,8 @@ HeapTupleSatisfiesUpperUnboundedInternalTimeQual(HeapTuple tuple,
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	if (TransactionIdIsCurrentTransactionId((TransactionId)tuple->t_xmax)) {
 | 
			
		||||
	    return (CommandIdIsCurrentCommandId(tuple->t_cmin));
 | 
			
		||||
	    return (CommandIdGEScanCommandId(tuple->t_cmin));
 | 
			
		||||
	    /* it looks like error		      ^^^^ */
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	if (!TransactionIdDidCommit((TransactionId)tuple->t_xmax)) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user