forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit5100010
committed
Teach VACUUM to bypass unnecessary index vacuuming.
VACUUM has never needed to call ambulkdelete() for each index in caseswhere there are precisely zero TIDs in its dead_tuples array by the endof its first pass over the heap (also its only pass over the heap inthis scenario). Index vacuuming is simply not required when thishappens. Index cleanup will still go ahead, but in practice most callsto amvacuumcleanup() are usually no-ops when there were zero precedingambulkdelete() calls. In short, VACUUM has generally managed to avoidindex scans when there were clearly no index tuples to delete fromindexes. But cases with _close to_ no index tuples to delete wereanother matter -- a round of ambulkdelete() calls took place (one perindex), each of which performed a full index scan.VACUUM now behaves just as if there were zero index tuples to delete incases where there are in fact "virtually zero" such tuples. That is, itcan now bypass index vacuuming and heap vacuuming as an optimization(though not index cleanup). Whether or not VACUUM bypasses indexes isdetermined dynamically, based on the just-observed number of heap pagesin the table that have one or more LP_DEAD items (LP_DEAD items in heappages have a 1:1 correspondence with index tuples that still need to bedeleted from each index in the worst case).We only skip index vacuuming when 2% or less of the table's pages haveone or more LP_DEAD items -- bypassing index vacuuming as anoptimization must not noticeably impede setting bits in the visibilitymap. As a further condition, the dead_tuples array (i.e. VACUUM's arrayof LP_DEAD item TIDs) must not exceed 32MB at the point that the firstpass over the heap finishes, which is also when the decision to bypassis made. (The VACUUM must also have been able to fit all TIDs in itsmaintenance_work_mem-bound dead_tuples space, though with a defaultmaintenance_work_mem setting it can't matter.)This avoids surprising jumps in the duration and overhead of routinevacuuming with workloads where successive VACUUM operations consistentlyhave almost zero dead index tuples. The number of LP_DEAD items maywell accumulate over multiple VACUUM operations, before finally thethreshold is crossed and VACUUM performs conventional index vacuuming.Even then, the optimization will have avoided a great deal of largelyunnecessary index vacuuming.In the future we may teach VACUUM to skip index vacuuming on a per-indexbasis, using a much more sophisticated approach. For now we onlyconsider the extreme cases, where we can be quite confident that indexvacuuming just isn't worth it using simple heuristics.Also log information about how many heap pages have one or more LP_DEADitems when autovacuum logging is enabled.Author: Masahiko Sawada <sawada.mshk@gmail.com>Author: Peter Geoghegan <pg@bowt.ie>Discussion:https://postgr.es/m/CAD21AoD0SkE11fMw4jD4RENAwBMcw1wasVnwpJVw3tVqPOQgAw@mail.gmail.comDiscussion:https://postgr.es/m/CAH2-WzmkebqPd4MVGuPTOS9bMFvp9MDs5cRTCOsv1rQJ3jCbXw@mail.gmail.com1 parentbc70728 commit5100010
1 file changed
+128
-10
lines changedLines changed: 128 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
103 | 103 |
| |
104 | 104 |
| |
105 | 105 |
| |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
106 | 112 |
| |
107 | 113 |
| |
108 | 114 |
| |
| |||
401 | 407 |
| |
402 | 408 |
| |
403 | 409 |
| |
404 |
| - | |
| 410 | + | |
405 | 411 |
| |
406 | 412 |
| |
407 | 413 |
| |
| |||
760 | 766 |
| |
761 | 767 |
| |
762 | 768 |
| |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
763 | 794 |
| |
764 | 795 |
| |
765 | 796 |
| |
| |||
850 | 881 |
| |
851 | 882 |
| |
852 | 883 |
| |
853 |
| - | |
| 884 | + | |
| 885 | + | |
854 | 886 |
| |
855 | 887 |
| |
856 | 888 |
| |
| |||
1108 | 1140 |
| |
1109 | 1141 |
| |
1110 | 1142 |
| |
1111 |
| - | |
| 1143 | + | |
| 1144 | + | |
1112 | 1145 |
| |
1113 | 1146 |
| |
1114 | 1147 |
| |
| |||
1475 | 1508 |
| |
1476 | 1509 |
| |
1477 | 1510 |
| |
1478 |
| - | |
1479 |
| - | |
1480 |
| - | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
1481 | 1515 |
| |
1482 | 1516 |
| |
1483 | 1517 |
| |
| |||
1522 | 1556 |
| |
1523 | 1557 |
| |
1524 | 1558 |
| |
1525 |
| - | |
1526 | 1559 |
| |
1527 |
| - | |
| 1560 | + | |
1528 | 1561 |
| |
1529 | 1562 |
| |
1530 | 1563 |
| |
| |||
1555 | 1588 |
| |
1556 | 1589 |
| |
1557 | 1590 |
| |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
1558 | 1601 |
| |
1559 | 1602 |
| |
1560 | 1603 |
| |
| |||
1983 | 2026 |
| |
1984 | 2027 |
| |
1985 | 2028 |
| |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
1986 | 2034 |
| |
1987 | 2035 |
| |
1988 | 2036 |
| |
1989 | 2037 |
| |
1990 | 2038 |
| |
1991 | 2039 |
| |
1992 |
| - | |
| 2040 | + | |
1993 | 2041 |
| |
| 2042 | + | |
| 2043 | + | |
1994 | 2044 |
| |
1995 | 2045 |
| |
1996 | 2046 |
| |
| |||
2003 | 2053 |
| |
2004 | 2054 |
| |
2005 | 2055 |
| |
2006 |
| - | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
2007 | 2125 |
| |
2008 | 2126 |
| |
2009 | 2127 |
| |
|
0 commit comments
Comments
(0)