Skip to content

Commit f03d228

Browse files
committed
HeapTupleSatisfiesVacuum() needs to be more careful about the
difference between INSERT_IN_PROGRESS and DELETE_IN_PROGRESS for tuples inserted and then deleted by a concurrent transaction. Example of bug: regression=# create table foo (f1 int); CREATE TABLE regression=# begin; BEGIN regression=# insert into foo values(1); INSERT 195531 1 regression=# delete from foo; DELETE 1 regression=# insert into foo values(1); INSERT 195532 1 regression=# create unique index fooi on foo(f1); ERROR: could not create unique index DETAIL: Table contains duplicated values.
1 parent 278a13f commit f03d228

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/backend/utils/time/tqual.c

Lines changed: 11 additions & 2 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.67 2003/08/04 02:40:09 momjian Exp $
19+
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.68 2003/09/22 00:47:23 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -868,7 +868,16 @@ HeapTupleSatisfiesVacuum(HeapTupleHeader tuple, TransactionId OldestXmin)
868868
}
869869
}
870870
else if (TransactionIdIsInProgress(HeapTupleHeaderGetXmin(tuple)))
871-
return HEAPTUPLE_INSERT_IN_PROGRESS;
871+
{
872+
if (tuple->t_infomask & HEAP_XMAX_INVALID) /* xid invalid */
873+
return HEAPTUPLE_INSERT_IN_PROGRESS;
874+
Assert(HeapTupleHeaderGetXmin(tuple) ==
875+
HeapTupleHeaderGetXmax(tuple));
876+
if (tuple->t_infomask & HEAP_MARKED_FOR_UPDATE)
877+
return HEAPTUPLE_INSERT_IN_PROGRESS;
878+
/* inserted and then deleted by same xact */
879+
return HEAPTUPLE_DELETE_IN_PROGRESS;
880+
}
872881
else if (TransactionIdDidCommit(HeapTupleHeaderGetXmin(tuple)))
873882
tuple->t_infomask |= HEAP_XMIN_COMMITTED;
874883
else

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy