forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitb4b6923
committed
Fix VACUUM so that it always updates pg_class.reltuples/relpages.
When we added the ability for vacuum to skip heap pages by consulting thevisibility map, we made it just not update the reltuples/relpagesstatistics if it skipped any pages. But this could leave us with extremelyout-of-date stats for a table that contains any unchanging areas,especially for TOAST tables which never get processed by ANALYZE. Inparticular this could result in autovacuum making poor decisions about whento process the table, as in recent report from Florian Helmberger. And ingeneral it's a bad idea to not update the stats at all. Instead, use theprevious values of reltuples/relpages as an estimate of the tuple densityin unvisited pages. This approach results in a "moving average" estimateof reltuples, which should converge to the correct value over multipleVACUUM and ANALYZE cycles even when individual measurements aren't verygood.This new method for updating reltuples is used by both VACUUM and ANALYZE,with the result that we no longer need the grotty interconnections thatcaused ANALYZE to not update the stats depending on what had happenedin the parent VACUUM command.Also, fix the logic for skipping all-visible pages during VACUUM so that itlooks ahead rather than behind to decide what to do, as per a suggestionfrom Greg Stark. This eliminates useless scanning of all-visible pages atthe start of the relation or just after a not-all-visible page. Inparticular, the first few pages of the relation will not be invariablyincluded in the scanned pages, which seems to help in not overweightingthem in the reltuples estimate.Back-patch to 8.4, where the visibility map was introduced.1 parent3001b76 commitb4b6923
6 files changed
+228
-129
lines changedLines changed: 24 additions & 35 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
84 | 84 |
| |
85 | 85 |
| |
86 | 86 |
| |
87 |
| - | |
88 |
| - | |
| 87 | + | |
89 | 88 |
| |
90 | 89 |
| |
91 | 90 |
| |
| |||
115 | 114 |
| |
116 | 115 |
| |
117 | 116 |
| |
118 |
| - | |
119 |
| - | |
120 |
| - | |
121 |
| - | |
122 |
| - | |
123 |
| - | |
124 |
| - | |
125 |
| - | |
126 | 117 |
| |
127 | 118 |
| |
128 |
| - | |
129 |
| - | |
| 119 | + | |
130 | 120 |
| |
131 | 121 |
| |
132 | 122 |
| |
| |||
238 | 228 |
| |
239 | 229 |
| |
240 | 230 |
| |
241 |
| - | |
| 231 | + | |
242 | 232 |
| |
243 | 233 |
| |
244 | 234 |
| |
245 | 235 |
| |
246 | 236 |
| |
247 |
| - | |
| 237 | + | |
248 | 238 |
| |
249 | 239 |
| |
250 | 240 |
| |
| |||
267 | 257 |
| |
268 | 258 |
| |
269 | 259 |
| |
270 |
| - | |
271 |
| - | |
| 260 | + | |
272 | 261 |
| |
273 | 262 |
| |
274 | 263 |
| |
| |||
437 | 426 |
| |
438 | 427 |
| |
439 | 428 |
| |
440 |
| - | |
| 429 | + | |
441 | 430 |
| |
442 |
| - | |
| 431 | + | |
443 | 432 |
| |
444 | 433 |
| |
445 | 434 |
| |
| |||
549 | 538 |
| |
550 | 539 |
| |
551 | 540 |
| |
552 |
| - | |
553 |
| - | |
| 541 | + | |
| 542 | + | |
554 | 543 |
| |
555 |
| - | |
| 544 | + | |
556 | 545 |
| |
557 | 546 |
| |
558 | 547 |
| |
| |||
562 | 551 |
| |
563 | 552 |
| |
564 | 553 |
| |
565 |
| - | |
| 554 | + | |
566 | 555 |
| |
567 | 556 |
| |
568 | 557 |
| |
| |||
577 | 566 |
| |
578 | 567 |
| |
579 | 568 |
| |
580 |
| - | |
581 |
| - | |
582 |
| - | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
583 | 572 |
| |
584 | 573 |
| |
585 |
| - | |
586 |
| - | |
| 574 | + | |
587 | 575 |
| |
588 | 576 |
| |
589 | 577 |
| |
| |||
1243 | 1231 |
| |
1244 | 1232 |
| |
1245 | 1233 |
| |
1246 |
| - | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
1247 | 1238 |
| |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
1248 | 1243 |
| |
1249 |
| - | |
1250 |
| - | |
1251 |
| - | |
1252 |
| - | |
| 1244 | + | |
1253 | 1245 |
| |
1254 |
| - | |
1255 |
| - | |
1256 | 1246 |
| |
1257 |
| - | |
1258 | 1247 |
| |
1259 | 1248 |
| |
1260 | 1249 |
| |
|
Lines changed: 82 additions & 16 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
20 | 20 |
| |
21 | 21 |
| |
22 | 22 |
| |
| 23 | + | |
| 24 | + | |
23 | 25 |
| |
24 | 26 |
| |
25 | 27 |
| |
| |||
62 | 64 |
| |
63 | 65 |
| |
64 | 66 |
| |
65 |
| - | |
| 67 | + | |
66 | 68 |
| |
67 | 69 |
| |
68 | 70 |
| |
| |||
219 | 221 |
| |
220 | 222 |
| |
221 | 223 |
| |
222 |
| - | |
223 | 224 |
| |
224 | 225 |
| |
225 | 226 |
| |
226 |
| - | |
227 |
| - | |
| 227 | + | |
228 | 228 |
| |
229 | 229 |
| |
230 | 230 |
| |
| |||
241 | 241 |
| |
242 | 242 |
| |
243 | 243 |
| |
244 |
| - | |
| 244 | + | |
245 | 245 |
| |
246 | 246 |
| |
247 | 247 |
| |
| |||
453 | 453 |
| |
454 | 454 |
| |
455 | 455 |
| |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
456 | 529 |
| |
457 | 530 |
| |
458 | 531 |
| |
| |||
480 | 553 |
| |
481 | 554 |
| |
482 | 555 |
| |
483 |
| - | |
| 556 | + | |
484 | 557 |
| |
485 | 558 |
| |
486 | 559 |
| |
| |||
758 | 831 |
| |
759 | 832 |
| |
760 | 833 |
| |
761 |
| - | |
762 |
| - | |
763 |
| - | |
764 | 834 |
| |
765 | 835 |
| |
766 | 836 |
| |
767 |
| - | |
768 |
| - | |
| 837 | + | |
769 | 838 |
| |
770 | 839 |
| |
771 | 840 |
| |
| |||
775 | 844 |
| |
776 | 845 |
| |
777 | 846 |
| |
778 |
| - | |
779 |
| - | |
780 |
| - | |
781 | 847 |
| |
782 | 848 |
| |
783 | 849 |
| |
| |||
971 | 1037 |
| |
972 | 1038 |
| |
973 | 1039 |
| |
974 |
| - | |
| 1040 | + | |
975 | 1041 |
| |
976 | 1042 |
| |
977 | 1043 |
| |
| |||
997 | 1063 |
| |
998 | 1064 |
| |
999 | 1065 |
| |
1000 |
| - | |
| 1066 | + | |
1001 | 1067 |
| |
1002 | 1068 |
| |
1003 | 1069 |
| |
|
0 commit comments
Comments
(0)