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

Commit74388a1

Browse files
Avoid VACUUM reltuples distortion.
Add a heuristic that avoids distortion in the pg_class.reltuplesestimates used by VACUUM. Without the heuristic, successive manuallyrun VACUUM commands (run against a table that is never modified afterinitial bulk loading) will scan the same page in each VACUUM operation.Eventually pg_class.reltuples may reach the point where one single heappage is accidentally considered highly representative of the entiretable. This is likely to be completely wrong, since the last heap pagetypically has fewer tuples than average for the table.It's not obvious that this was a problem prior to commit44fa848, whichmade vacuumlazy.c consistently scan the last heap page (even when it isall-visible in the visibility map). It seems possible that there weremore subtle variants of the same problem that went unnoticed for quitesome time, though. Commit44fa848 simplified certain aspects of whenand how relation truncation was considered, but it did not introduce the"scan the last page" behavior. Essentially the same behavior wasintroduced much earlier, in commite842908. It was conditioned onwhether or not truncation looked promising towards the end of theinitial heap pass by VACUUM until recently, which was at least somewhatprotective. That doesn't seem like something that we should be relyingon, though.Author: Peter Geoghegan <pg@bowt.ie>Discussion:https://postgr.es/m/CAH2-WzkNKORurux459M64mR63Aw4Jq7MBRVcX=CvALqN3A88WA@mail.gmail.com
1 parentd61a361 commit74388a1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎src/backend/commands/vacuum.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,25 @@ vac_estimate_reltuples(Relation relation,
12381238
if (scanned_pages==0)
12391239
returnold_rel_tuples;
12401240

1241+
/*
1242+
* When successive VACUUM commands scan the same few pages again and
1243+
* again, without anything from the table really changing, there is a risk
1244+
* that our beliefs about tuple density will gradually become distorted.
1245+
* It's particularly important to avoid becoming confused in this way due
1246+
* to vacuumlazy.c implementation details. For example, the tendency for
1247+
* our caller to always scan the last heap page should not ever cause us
1248+
* to believe that every page in the table must be just like the last
1249+
* page.
1250+
*
1251+
* We apply a heuristic to avoid these problems: if the relation is
1252+
* exactly the same size as it was at the end of the last VACUUM, and only
1253+
* a few of its pages (less than a quasi-arbitrary threshold of 2%) were
1254+
* scanned by this VACUUM, assume that reltuples has not changed at all.
1255+
*/
1256+
if (old_rel_pages==total_pages&&
1257+
scanned_pages< (double)total_pages*0.02)
1258+
returnold_rel_tuples;
1259+
12411260
/*
12421261
* If old density is unknown, we can't do much except scale up
12431262
* scanned_tuples to match total_pages.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp