From e6858e665731c0f56d3ecc9fbb245c32d24f8ef7 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 14 Oct 2011 17:23:01 -0400 Subject: Measure the number of all-visible pages for use in index-only scan costing. Add a column pg_class.relallvisible to remember the number of pages that were all-visible according to the visibility map as of the last VACUUM (or ANALYZE, or some other operations that update pg_class.relpages). Use relallvisible/relpages, instead of an arbitrary constant, to estimate how many heap page fetches can be avoided during an index-only scan. This is pretty primitive and will no doubt see refinements once we've acquired more field experience with the index-only scan mechanism, but it's way better than using a constant. Note: I had to adjust an underspecified query in the window.sql regression test, because it was changing answers when the plan changed to use an index-only scan. Some of the adjacent tests perhaps should be adjusted as well, but I didn't do that here. --- src/backend/commands/analyze.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/backend/commands/analyze.c') diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 18d44c572c7..32985a4a0a0 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -19,6 +19,7 @@ #include "access/transam.h" #include "access/tupconvert.h" #include "access/tuptoaster.h" +#include "access/visibilitymap.h" #include "access/xact.h" #include "catalog/index.h" #include "catalog/indexing.h" @@ -534,7 +535,10 @@ do_analyze_rel(Relation onerel, VacuumStmt *vacstmt, bool inh) if (!inh) vac_update_relstats(onerel, RelationGetNumberOfBlocks(onerel), - totalrows, hasindex, InvalidTransactionId); + totalrows, + visibilitymap_count(onerel), + hasindex, + InvalidTransactionId); /* * Same for indexes. Vacuum always scans all indexes, so if we're part of @@ -551,7 +555,10 @@ do_analyze_rel(Relation onerel, VacuumStmt *vacstmt, bool inh) totalindexrows = ceil(thisdata->tupleFract * totalrows); vac_update_relstats(Irel[ind], RelationGetNumberOfBlocks(Irel[ind]), - totalindexrows, false, InvalidTransactionId); + totalindexrows, + 0, + false, + InvalidTransactionId); } } -- cgit v1.2.3