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

Commit5853662

Browse files
committed
Reduce the size of memory allocations by lazy vacuum when processing a small
table, by allocating just enough for a hardcoded number of dead tuples perpage. The current estimate is 200 dead tuples per page.Per reports from Jeff Amiel, Erik Jones and Marko Kreen, and subsequentdiscussion.CVS: ----------------------------------------------------------------------CVS: Enter Log. Lines beginning with `CVS:' are removed automaticallyCVS:CVS: Committing in .CVS:CVS: Modified Files:CVS: commands/vacuumlazy.cCVS: ----------------------------------------------------------------------
1 parent48f7e64 commit5853662

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

‎src/backend/commands/vacuumlazy.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
* on the number of tuples and pages we will keep track of at once.
1212
*
1313
* We are willing to use at most maintenance_work_mem memory space to keep
14-
* track of dead tuples. We initially allocate an array of TIDs of that size.
15-
* If the array threatens to overflow, we suspend the heap scan phase and
16-
* perform a pass of index cleanup and page compaction, then resume the heap
17-
* scan with an empty TID array.
14+
* track of dead tuples. We initially allocate an array of TIDs of that size,
15+
* with an upper limit that depends on table size (this limit ensures we don't
16+
* allocate a huge area uselessly for vacuuming small tables). If the array
17+
* threatens to overflow, we suspend the heap scan phase and perform a pass of
18+
* index cleanup and page compaction, then resume the heap scan with an empty
19+
* TID array.
1820
*
1921
* We can limit the storage for page free space to MaxFSMPages entries,
2022
* since that's the most the free space map will be willing to remember
@@ -36,7 +38,7 @@
3638
*
3739
*
3840
* IDENTIFICATION
39-
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.99 2007/09/24 03:12:23 tgl Exp $
41+
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.100 2007/09/24 03:52:55 alvherre Exp $
4042
*
4143
*-------------------------------------------------------------------------
4244
*/
@@ -68,6 +70,12 @@
6870
#defineREL_TRUNCATE_MINIMUM1000
6971
#defineREL_TRUNCATE_FRACTION16
7072

73+
/*
74+
* Guesstimation of number of dead tuples per page. This is used to
75+
* provide an upper limit to memory allocated when vacuuming small
76+
* tables.
77+
*/
78+
#defineLAZY_ALLOC_TUPLES200
7179

7280
typedefstructLVRelStats
7381
{
@@ -1001,6 +1009,11 @@ lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks)
10011009
maxtuples= (maintenance_work_mem*1024L) /sizeof(ItemPointerData);
10021010
maxtuples=Min(maxtuples,INT_MAX);
10031011
maxtuples=Min(maxtuples,MaxAllocSize /sizeof(ItemPointerData));
1012+
1013+
/* curious coding here to ensure the multiplication can't overflow */
1014+
if ((BlockNumber) (maxtuples /LAZY_ALLOC_TUPLES)>relblocks)
1015+
maxtuples=relblocks*LAZY_ALLOC_TUPLES;
1016+
10041017
/* stay sane if small maintenance_work_mem */
10051018
maxtuples=Max(maxtuples,MaxHeapTuplesPerPage);
10061019
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp