mirror of
https://github.com/postgres/postgres.git
synced 2025-10-27 00:12:01 +03:00
Improve the IndexVacuumInfo/IndexBulkDeleteResult API to allow somewhat sane
behavior in cases where we don't know the heap tuple count accurately; in particular partial vacuum, but this also makes the API a bit more useful for ANALYZE. This patch adds "estimated_count" flags to both structs so that an approximate count can be flagged as such, and adjusts the logic so that approximate counts are not used for updating pg_class.reltuples. This fixes my previous complaint that VACUUM was putting ridiculous values into pg_class.reltuples for indexes. The actual impact of that bug is limited, because the planner only pays attention to reltuples for an index if the index is partial; which probably explains why beta testers hadn't noticed a degradation in plan quality from it. But it needs to be fixed. The whole thing is a bit messy and should be redesigned in future, because reltuples now has the potential to drift quite far away from reality when a long period elapses with no non-partial vacuums. But this is as good as it's going to get for 8.4.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/genam.h,v 1.76 2009/03/24 20:17:14 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/include/access/genam.h,v 1.77 2009/06/06 22:13:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -34,14 +34,17 @@ typedef struct IndexBuildResult
|
||||
/*
|
||||
* Struct for input arguments passed to ambulkdelete and amvacuumcleanup
|
||||
*
|
||||
* Note that num_heap_tuples will not be valid during ambulkdelete,
|
||||
* only amvacuumcleanup.
|
||||
* num_heap_tuples is accurate only when estimated_count is false;
|
||||
* otherwise it's just an estimate (currently, the estimate is the
|
||||
* prior value of the relation's pg_class.reltuples field). It will
|
||||
* always just be an estimate during ambulkdelete.
|
||||
*/
|
||||
typedef struct IndexVacuumInfo
|
||||
{
|
||||
Relation index; /* the index being vacuumed */
|
||||
bool vacuum_full; /* VACUUM FULL (we have exclusive lock) */
|
||||
bool analyze_only; /* ANALYZE (without any actual vacuum) */
|
||||
bool estimated_count; /* num_heap_tuples is an estimate */
|
||||
int message_level; /* ereport level for progress messages */
|
||||
double num_heap_tuples; /* tuples remaining in heap */
|
||||
BufferAccessStrategy strategy; /* access strategy for reads */
|
||||
@@ -60,12 +63,15 @@ typedef struct IndexVacuumInfo
|
||||
*
|
||||
* Note: pages_removed is the amount by which the index physically shrank,
|
||||
* if any (ie the change in its total size on disk). pages_deleted and
|
||||
* pages_free refer to free space within the index file.
|
||||
* pages_free refer to free space within the index file. Some index AMs
|
||||
* may compute num_index_tuples by reference to num_heap_tuples, in which
|
||||
* case they should copy the estimated_count field from IndexVacuumInfo.
|
||||
*/
|
||||
typedef struct IndexBulkDeleteResult
|
||||
{
|
||||
BlockNumber num_pages; /* pages remaining in index */
|
||||
BlockNumber pages_removed; /* # removed during vacuum operation */
|
||||
bool estimated_count; /* num_index_tuples is an estimate */
|
||||
double num_index_tuples; /* tuples remaining */
|
||||
double tuples_removed; /* # removed during vacuum operation */
|
||||
BlockNumber pages_deleted; /* # unused pages in index */
|
||||
|
||||
Reference in New Issue
Block a user