Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6f10eb2

Browse files
committed
Refactor heap_page_prune so that instead of changing item states on-the-fly,
it accumulates the set of changes to be made and then applies them. It hadto accumulate the set of changes anyway to prepare a WAL record for thepruning action, so this isn't an enormous change; the only new complexity isto not doubly mark tuples that are visited twice in the scan. The mainadvantage is that we can substantially reduce the scope of the criticalsection in which the changes are applied, thus avoiding PANIC in foreseeablecases like running out of memory in inval.c. A nice secondary advantage isthat it is now far clearer that WAL replay will actually do the same thingthat the original pruning did.This commit doesn't do anything about the open problem thatCacheInvalidateHeapTuple doesn't have the right semantics for a CTID changecaused by collapsing out a redirect pointer. But whatever we do about that,it'll be a good idea to not do it inside a critical section.
1 parentcc05d05 commit6f10eb2

File tree

3 files changed

+294
-197
lines changed

3 files changed

+294
-197
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.250 2008/03/04 19:54:06 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.251 2008/03/08 21:57:59 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -3967,11 +3967,13 @@ heap_xlog_clean(XLogRecPtr lsn, XLogRecord *record, bool clean_move)
39673967
Relationreln;
39683968
Bufferbuffer;
39693969
Pagepage;
3970-
OffsetNumber*offnum;
39713970
OffsetNumber*end;
3971+
OffsetNumber*redirected;
3972+
OffsetNumber*nowdead;
3973+
OffsetNumber*nowunused;
39723974
intnredirected;
39733975
intndead;
3974-
inti;
3976+
intnunused;
39753977

39763978
if (record->xl_info&XLR_BKP_BLOCK_1)
39773979
return;
@@ -3990,61 +3992,24 @@ heap_xlog_clean(XLogRecPtr lsn, XLogRecord *record, bool clean_move)
39903992

39913993
nredirected=xlrec->nredirected;
39923994
ndead=xlrec->ndead;
3993-
offnum= (OffsetNumber*) ((char*)xlrec+SizeOfHeapClean);
39943995
end= (OffsetNumber*) ((char*)xlrec+record->xl_len);
3995-
3996-
/* Update all redirected or moved line pointers */
3997-
for (i=0;i<nredirected;i++)
3998-
{
3999-
OffsetNumberfromoff=*offnum++;
4000-
OffsetNumbertooff=*offnum++;
4001-
ItemIdfromlp=PageGetItemId(page,fromoff);
4002-
4003-
if (clean_move)
4004-
{
4005-
/* Physically move the "to" item to the "from" slot */
4006-
ItemIdtolp=PageGetItemId(page,tooff);
4007-
HeapTupleHeaderhtup;
4008-
4009-
*fromlp=*tolp;
4010-
ItemIdSetUnused(tolp);
4011-
4012-
/* We also have to clear the tuple's heap-only bit */
4013-
Assert(ItemIdIsNormal(fromlp));
4014-
htup= (HeapTupleHeader)PageGetItem(page,fromlp);
4015-
Assert(HeapTupleHeaderIsHeapOnly(htup));
4016-
HeapTupleHeaderClearHeapOnly(htup);
4017-
}
4018-
else
4019-
{
4020-
/* Just insert a REDIRECT link at fromoff */
4021-
ItemIdSetRedirect(fromlp,tooff);
4022-
}
4023-
}
4024-
4025-
/* Update all now-dead line pointers */
4026-
for (i=0;i<ndead;i++)
4027-
{
4028-
OffsetNumberoff=*offnum++;
4029-
ItemIdlp=PageGetItemId(page,off);
4030-
4031-
ItemIdSetDead(lp);
4032-
}
4033-
4034-
/* Update all now-unused line pointers */
4035-
while (offnum<end)
4036-
{
4037-
OffsetNumberoff=*offnum++;
4038-
ItemIdlp=PageGetItemId(page,off);
4039-
4040-
ItemIdSetUnused(lp);
4041-
}
3996+
redirected= (OffsetNumber*) ((char*)xlrec+SizeOfHeapClean);
3997+
nowdead=redirected+ (nredirected*2);
3998+
nowunused=nowdead+ndead;
3999+
nunused= (end-nowunused);
4000+
Assert(nunused >=0);
4001+
4002+
/* Update all item pointers per the record, and repair fragmentation */
4003+
heap_page_prune_execute(reln,buffer,
4004+
redirected,nredirected,
4005+
nowdead,ndead,
4006+
nowunused,nunused,
4007+
clean_move);
40424008

40434009
/*
4044-
*Finally, repair any fragmentation, and update the page'shint bit about
4045-
*whether it has free pointers.
4010+
*Note: we don't worry about updating the page'sprunability hints.
4011+
*At worst this will cause an extra prune cycle to occur soon.
40464012
*/
4047-
PageRepairFragmentation(page);
40484013

40494014
PageSetLSN(page,lsn);
40504015
PageSetTLI(page,ThisTimeLineID);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp