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

Commit73ed6d6

Browse files
committed
Remove lazy_update_relstats; go back to having VACUUM just record the
actual number of unremoved tuples as pg_class.reltuples. The idea oftrying to estimate a steady state condition still seems attractive, butthis particular implementation crashed and burned ...
1 parentadb1a6e commit73ed6d6

File tree

1 file changed

+13
-60
lines changed

1 file changed

+13
-60
lines changed

‎src/backend/commands/vacuumlazy.c

Lines changed: 13 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*
3232
*
3333
* 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 $
3535
*
3636
*-------------------------------------------------------------------------
3737
*/
@@ -107,10 +107,6 @@ static int lazy_vacuum_page(Relation onerel, BlockNumber blkno, Buffer buffer,
107107
staticvoidlazy_truncate_heap(Relationonerel,LVRelStats*vacrelstats);
108108
staticBlockNumbercount_nondeletable_pages(Relationonerel,
109109
LVRelStats*vacrelstats);
110-
staticvoidlazy_update_relstats(Relationrel,BlockNumbernum_pages,
111-
BlockNumberpages_removed,
112-
doublenum_tuples,doubletuples_removed,
113-
boolhasindex);
114110
staticvoidlazy_space_alloc(LVRelStats*vacrelstats,BlockNumberrelblocks);
115111
staticvoidlazy_record_dead_tuple(LVRelStats*vacrelstats,
116112
ItemPointeritemptr);
@@ -180,10 +176,10 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
180176
lazy_update_fsm(onerel,vacrelstats);
181177

182178
/* 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);
187183
}
188184

189185

@@ -622,9 +618,10 @@ lazy_scan_index(Relation indrel, LVRelStats *vacrelstats)
622618
return;
623619

624620
/* 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);
628625

629626
ereport(elevel,
630627
(errmsg("index \"%s\" now contains %.0f row versions in %u pages",
@@ -697,9 +694,10 @@ lazy_vacuum_index(Relation indrel,
697694
*index_pages_removed+=stats->pages_removed;
698695

699696
/* 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);
703701

704702
ereport(elevel,
705703
(errmsg("index \"%s\" now contains %.0f row versions in %u pages",
@@ -922,51 +920,6 @@ count_nondeletable_pages(Relation onerel, LVRelStats *vacrelstats)
922920
returnvacrelstats->nonempty_pages;
923921
}
924922

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-
970923
/*
971924
* lazy_space_alloc - space allocation decisions for lazy vacuum
972925
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp