|
31 | 31 | *
|
32 | 32 | *
|
33 | 33 | * IDENTIFICATION
|
34 |
| - * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.51 2005/03/20 22:00:52 tgl Exp $ |
| 34 | + * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.52 2005/03/25 22:51:31 tgl Exp $ |
35 | 35 | *
|
36 | 36 | *-------------------------------------------------------------------------
|
37 | 37 | */
|
@@ -107,10 +107,6 @@ static int lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer,
|
107 | 107 | staticvoidlazy_truncate_heap(Relationonerel,LVRelStats*vacrelstats);
|
108 | 108 | staticBlockNumbercount_nondeletable_pages(Relationonerel,
|
109 | 109 | LVRelStats*vacrelstats);
|
110 |
| -staticvoidlazy_update_relstats(Relationrel,BlockNumbernum_pages, |
111 |
| -BlockNumberpages_removed, |
112 |
| -doublenum_tuples,doubletuples_removed, |
113 |
| -boolhasindex); |
114 | 110 | staticvoidlazy_space_alloc(LVRelStats*vacrelstats,BlockNumberrelblocks);
|
115 | 111 | staticvoidlazy_record_dead_tuple(LVRelStats*vacrelstats,
|
116 | 112 | ItemPointeritemptr);
|
@@ -180,10 +176,10 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
|
180 | 176 | lazy_update_fsm(onerel,vacrelstats);
|
181 | 177 |
|
182 | 178 | /* Update statistics in pg_class */
|
183 |
| -lazy_update_relstats(onerel,vacrelstats->rel_pages, |
184 |
| -vacrelstats->pages_removed, |
185 |
| -vacrelstats->rel_tuples,vacrelstats->tuples_deleted, |
186 |
| -hasindex); |
| 179 | +vac_update_relstats(RelationGetRelid(onerel), |
| 180 | +vacrelstats->rel_pages, |
| 181 | +vacrelstats->rel_tuples, |
| 182 | +hasindex); |
187 | 183 | }
|
188 | 184 |
|
189 | 185 |
|
@@ -622,9 +618,10 @@ lazy_scan_index(Relation indrel, LVRelStats *vacrelstats)
|
622 | 618 | return;
|
623 | 619 |
|
624 | 620 | /* now update statistics in pg_class */
|
625 |
| -lazy_update_relstats(indrel,stats->num_pages,stats->pages_removed, |
626 |
| -stats->num_index_tuples,stats->tuples_removed, |
627 |
| - false); |
| 621 | +vac_update_relstats(RelationGetRelid(indrel), |
| 622 | +stats->num_pages, |
| 623 | +stats->num_index_tuples, |
| 624 | +false); |
628 | 625 |
|
629 | 626 | ereport(elevel,
|
630 | 627 | (errmsg("index \"%s\" now contains %.0f row versions in %u pages",
|
@@ -697,9 +694,10 @@ lazy_vacuum_index(Relation indrel,
|
697 | 694 | *index_pages_removed+=stats->pages_removed;
|
698 | 695 |
|
699 | 696 | /* now update statistics in pg_class */
|
700 |
| -lazy_update_relstats(indrel,stats->num_pages,*index_pages_removed, |
701 |
| -stats->num_index_tuples,*index_tups_vacuumed, |
702 |
| - false); |
| 697 | +vac_update_relstats(RelationGetRelid(indrel), |
| 698 | +stats->num_pages, |
| 699 | +stats->num_index_tuples, |
| 700 | +false); |
703 | 701 |
|
704 | 702 | ereport(elevel,
|
705 | 703 | (errmsg("index \"%s\" now contains %.0f row versions in %u pages",
|
@@ -922,51 +920,6 @@ count_nondeletable_pages(Relation onerel, LVRelStats *vacrelstats)
|
922 | 920 | returnvacrelstats->nonempty_pages;
|
923 | 921 | }
|
924 | 922 |
|
925 |
| -/* |
926 |
| - * lazy_update_relstats - update pg_class statistics for a table or index |
927 |
| - * |
928 |
| - * We always want to set relpages to an accurate value. However, for lazy |
929 |
| - * VACUUM it seems best to set reltuples to the average of the number of |
930 |
| - * rows before vacuuming and the number after vacuuming, rather than just |
931 |
| - * using the number after vacuuming. This will result in the best average |
932 |
| - * performance in a steady-state situation where VACUUMs are performed |
933 |
| - * regularly on a table of roughly constant size, assuming that the physical |
934 |
| - * number of pages in the table stays about the same throughout. (Note that |
935 |
| - * we do not apply the same logic to VACUUM FULL, because it repacks the table |
936 |
| - * and thereby boosts the tuple density.) |
937 |
| - * |
938 |
| - * An important point is that when the table size has decreased a lot during |
939 |
| - * vacuuming, the old reltuples count might give an overestimate of the tuple |
940 |
| - * density. We handle this by scaling down the old reltuples count by the |
941 |
| - * fraction by which the table has shortened before we merge it with the |
942 |
| - * new reltuples count. In particular this means that when relpages goes to |
943 |
| - * zero, reltuples will immediately go to zero as well, causing the planner |
944 |
| - * to fall back on other estimation procedures as the table grows again. |
945 |
| - * |
946 |
| - * Because we do this math independently for the table and the indexes, it's |
947 |
| - * quite possible to end up with an index's reltuples different from the |
948 |
| - * table's, which is silly except in the case of partial indexes. We don't |
949 |
| - * worry too much about that here; the planner contains filtering logic to |
950 |
| - * ensure it only uses sane estimates. |
951 |
| - */ |
952 |
| -staticvoid |
953 |
| -lazy_update_relstats(Relationrel,BlockNumbernum_pages, |
954 |
| -BlockNumberpages_removed, |
955 |
| -doublenum_tuples,doubletuples_removed, |
956 |
| -boolhasindex) |
957 |
| -{ |
958 |
| -doubleold_num_tuples; |
959 |
| - |
960 |
| -old_num_tuples=num_tuples+tuples_removed; |
961 |
| -if (pages_removed>0) |
962 |
| -old_num_tuples *= (double)num_pages / (double) (num_pages+pages_removed); |
963 |
| -if (old_num_tuples>num_tuples) |
964 |
| -num_tuples=ceil((num_tuples+old_num_tuples)*0.5); |
965 |
| - |
966 |
| -vac_update_relstats(RelationGetRelid(rel),num_pages,num_tuples, |
967 |
| -hasindex); |
968 |
| -} |
969 |
| - |
970 | 923 | /*
|
971 | 924 | * lazy_space_alloc - space allocation decisions for lazy vacuum
|
972 | 925 | *
|
|