forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitd04900d
committed
When updating reltuples after ANALYZE, just extrapolate from our sample.
The existing logic for updating pg_class.reltuples trusted the samplingresults only for the pages ANALYZE actually visited, preferring tobelieve the previous tuple density estimate for all the unvisited pages.While there's some rationale for doing that for VACUUM (first thatVACUUM is likely to visit a very nonrandom subset of pages, and secondthat we know for sure that the unvisited pages did not change), there'sno such rationale for ANALYZE: by assumption, it's looked at an unbiasedrandom sample of the table's pages. Furthermore, in a very large tableANALYZE will have examined only a tiny fraction of the table's pages,meaning it cannot slew the overall density estimate very far at all.In a table that is physically growing, this causes reltuples to increasenearly proportionally to the change in relpages, regardless of what isactually happening in the table. This has been observed to cause reltuplesto become so much larger than reality that it effectively shuts offautovacuum, whose threshold for doing anything is a fraction of reltuples.(Getting to the point where that would happen seems to require someadditional, not well understood, conditions. But it's undeniable that ifreltuples is seriously off in a large table, ANALYZE alone will not fix itin any reasonable number of iterations, especially not if the table iscontinuing to grow.)Hence, restrict the use of vac_estimate_reltuples() to VACUUM alone,and in ANALYZE, just extrapolate from the sample pages on the assumptionthat they provide an accurate model of the whole table. If, by very badluck, they don't, at least another ANALYZE will fix it; in the old logica single bad estimate could cause problems indefinitely.In HEAD, let's remove vac_estimate_reltuples' is_analyze argumentaltogether; it was never used for anything and now it's totally pointless.But keep it in the back branches, in case any third-party code is callingthis function.Per bug #15005. Back-patch to all supported branches.David Gould, reviewed by Alexander Kuzmenkov, cosmetic changes by meDiscussion:https://postgr.es/m/20180117164916.3fdcf2e9@engels1 parent38f7831 commitd04900d
File tree
5 files changed
+27
-44
lines changed- contrib/pgstattuple
- src
- backend/commands
- include/commands
5 files changed
+27
-44
lines changedLines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
184 | 184 |
| |
185 | 185 |
| |
186 | 186 |
| |
187 |
| - | |
| 187 | + | |
188 | 188 |
| |
189 | 189 |
| |
190 | 190 |
| |
|
Lines changed: 11 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1249 | 1249 |
| |
1250 | 1250 |
| |
1251 | 1251 |
| |
1252 |
| - | |
1253 |
| - | |
1254 |
| - | |
1255 |
| - | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
1256 | 1257 |
| |
1257 |
| - | |
1258 |
| - | |
1259 |
| - | |
1260 |
| - | |
1261 | 1258 |
| |
| 1259 | + | |
| 1260 | + | |
1262 | 1261 |
| |
| 1262 | + | |
1263 | 1263 |
| |
| 1264 | + | |
| 1265 | + | |
1264 | 1266 |
| |
| 1267 | + | |
1265 | 1268 |
| |
1266 | 1269 |
| |
1267 | 1270 |
| |
|
Lines changed: 13 additions & 33 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
766 | 766 |
| |
767 | 767 |
| |
768 | 768 |
| |
769 |
| - | |
770 |
| - | |
771 |
| - | |
772 |
| - | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
773 | 773 |
| |
774 |
| - | |
775 |
| - | |
776 | 774 |
| |
777 | 775 |
| |
778 |
| - | |
| 776 | + | |
779 | 777 |
| |
780 | 778 |
| |
781 | 779 |
| |
782 | 780 |
| |
783 | 781 |
| |
784 | 782 |
| |
785 | 783 |
| |
786 |
| - | |
787 |
| - | |
788 |
| - | |
| 784 | + | |
| 785 | + | |
789 | 786 |
| |
790 | 787 |
| |
791 | 788 |
| |
| |||
809 | 806 |
| |
810 | 807 |
| |
811 | 808 |
| |
812 |
| - | |
813 |
| - | |
814 |
| - | |
815 |
| - | |
816 |
| - | |
817 |
| - | |
818 |
| - | |
819 |
| - | |
820 |
| - | |
821 |
| - | |
822 |
| - | |
823 |
| - | |
824 |
| - | |
825 |
| - | |
826 |
| - | |
827 |
| - | |
828 |
| - | |
829 |
| - | |
830 |
| - | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
831 | 812 |
| |
832 | 813 |
| |
833 |
| - | |
834 |
| - | |
835 |
| - | |
836 |
| - | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
837 | 817 |
| |
838 | 818 |
| |
839 | 819 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1286 | 1286 |
| |
1287 | 1287 |
| |
1288 | 1288 |
| |
1289 |
| - | |
| 1289 | + | |
1290 | 1290 |
| |
1291 | 1291 |
| |
1292 | 1292 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
162 | 162 |
| |
163 | 163 |
| |
164 | 164 |
| |
165 |
| - | |
| 165 | + | |
166 | 166 |
| |
167 | 167 |
| |
168 | 168 |
| |
|
0 commit comments
Comments
(0)