Skip to content

Commit 0affc29

Browse files
committed
Make sure that t_ctid is reset to equal t_self in heap_delete and
heap_mark4update; this avoids situations where a deleted tuple might look like it is chained to something else. Also, cause all the WAL redo routines to set t_ctid to equal t_self, rather than leaving it undefined as before. Make heap_xlog_clean set the page's LSN and SUI correctly. All per past discussions in pghackers, ranging back to last December.
1 parent 1e4c4f9 commit 0affc29

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/backend/access/heap/heapam.c

Lines changed: 24 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/access/heap/heapam.c,v 1.144 2002/08/06 02:36:33 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.145 2002/08/13 20:11:03 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1150,6 +1150,7 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid)
11501150

11511151
/* NO ELOG(ERROR) from here till changes are logged */
11521152
START_CRIT_SECTION();
1153+
11531154
RelationPutHeapTuple(relation, buffer, tup);
11541155

11551156
pgstat_count_heap_insert(&relation->pgstat_info);
@@ -1336,6 +1337,8 @@ heap_delete(Relation relation, ItemPointer tid,
13361337
HEAP_XMAX_INVALID | HEAP_MARKED_FOR_UPDATE);
13371338
HeapTupleHeaderSetXmax(tp.t_data, GetCurrentTransactionId());
13381339
HeapTupleHeaderSetCmax(tp.t_data, cid);
1340+
/* Make sure there is no forward chain link in t_ctid */
1341+
tp.t_data->t_ctid = tp.t_self;
13391342

13401343
/* XLOG stuff */
13411344
if (!relation->rd_istemp)
@@ -1844,6 +1847,8 @@ heap_mark4update(Relation relation, HeapTuple tuple, Buffer *buffer,
18441847
tuple->t_data->t_infomask |= HEAP_MARKED_FOR_UPDATE;
18451848
HeapTupleHeaderSetXmax(tuple->t_data, GetCurrentTransactionId());
18461849
HeapTupleHeaderSetCmax(tuple->t_data, cid);
1850+
/* Make sure there is no forward chain link in t_ctid */
1851+
tuple->t_data->t_ctid = *tid;
18471852

18481853
LockBuffer(*buffer, BUFFER_LOCK_UNLOCK);
18491854

@@ -2126,14 +2131,17 @@ heap_xlog_clean(bool redo, XLogRecPtr lsn, XLogRecord *record)
21262131
}
21272132

21282133
PageRepairFragmentation(page, NULL);
2134+
2135+
PageSetLSN(page, lsn);
2136+
PageSetSUI(page, ThisStartUpID); /* prev sui */
21292137
UnlockAndWriteBuffer(buffer);
21302138
}
21312139

21322140
static void
21332141
heap_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
21342142
{
21352143
xl_heap_delete *xlrec = (xl_heap_delete *) XLogRecGetData(record);
2136-
Relation reln = XLogOpenRelation(redo, RM_HEAP_ID, xlrec->target.node);
2144+
Relation reln;
21372145
Buffer buffer;
21382146
Page page;
21392147
OffsetNumber offnum;
@@ -2143,6 +2151,8 @@ heap_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
21432151
if (redo && (record->xl_info & XLR_BKP_BLOCK_1))
21442152
return;
21452153

2154+
reln = XLogOpenRelation(redo, RM_HEAP_ID, xlrec->target.node);
2155+
21462156
if (!RelationIsValid(reln))
21472157
return;
21482158

@@ -2186,6 +2196,8 @@ heap_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
21862196
HEAP_XMAX_INVALID | HEAP_MARKED_FOR_UPDATE);
21872197
HeapTupleHeaderSetXmax(htup, record->xl_xid);
21882198
HeapTupleHeaderSetCmax(htup, FirstCommandId);
2199+
/* Make sure there is no forward chain link in t_ctid */
2200+
htup->t_ctid = xlrec->target.tid;
21892201
PageSetLSN(page, lsn);
21902202
PageSetSUI(page, ThisStartUpID);
21912203
UnlockAndWriteBuffer(buffer);
@@ -2199,14 +2211,16 @@ static void
21992211
heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
22002212
{
22012213
xl_heap_insert *xlrec = (xl_heap_insert *) XLogRecGetData(record);
2202-
Relation reln = XLogOpenRelation(redo, RM_HEAP_ID, xlrec->target.node);
2214+
Relation reln;
22032215
Buffer buffer;
22042216
Page page;
22052217
OffsetNumber offnum;
22062218

22072219
if (redo && (record->xl_info & XLR_BKP_BLOCK_1))
22082220
return;
22092221

2222+
reln = XLogOpenRelation(redo, RM_HEAP_ID, xlrec->target.node);
2223+
22102224
if (!RelationIsValid(reln))
22112225
return;
22122226

@@ -2263,6 +2277,7 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
22632277
HeapTupleHeaderSetCmin(htup, FirstCommandId);
22642278
HeapTupleHeaderSetXmaxInvalid(htup);
22652279
HeapTupleHeaderSetCmax(htup, FirstCommandId);
2280+
htup->t_ctid = xlrec->target.tid;
22662281
if (reln->rd_rel->relhasoids)
22672282
{
22682283
AssertTupleDescHasOid(reln->rd_att);
@@ -2352,6 +2367,8 @@ heap_xlog_update(bool redo, XLogRecPtr lsn, XLogRecord *record, bool move)
23522367
~(HEAP_XMIN_COMMITTED | HEAP_XMIN_INVALID | HEAP_MOVED_IN);
23532368
htup->t_infomask |= HEAP_MOVED_OFF;
23542369
HeapTupleHeaderSetXvac(htup, record->xl_xid);
2370+
/* Make sure there is no forward chain link in t_ctid */
2371+
htup->t_ctid = xlrec->target.tid;
23552372
}
23562373
else
23572374
{
@@ -2363,6 +2380,8 @@ heap_xlog_update(bool redo, XLogRecPtr lsn, XLogRecord *record, bool move)
23632380
HEAP_XMAX_INVALID | HEAP_MARKED_FOR_UPDATE);
23642381
HeapTupleHeaderSetXmax(htup, record->xl_xid);
23652382
HeapTupleHeaderSetCmax(htup, FirstCommandId);
2383+
/* Set forward chain link in t_ctid */
2384+
htup->t_ctid = xlrec->newtid;
23662385
}
23672386
if (samepage)
23682387
goto newsame;
@@ -2465,6 +2484,8 @@ newsame:;
24652484
HeapTupleHeaderSetXmaxInvalid(htup);
24662485
HeapTupleHeaderSetCmax(htup, FirstCommandId);
24672486
}
2487+
/* Make sure there is no forward chain link in t_ctid */
2488+
htup->t_ctid = xlrec->newtid;
24682489

24692490
offnum = PageAddItem(page, (Item) htup, newlen, offnum,
24702491
LP_USED | OverwritePageMode);

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