1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-04 12:02:48 +03:00

Move various prechecks from vacuum() into ExecVacuum()

vacuum() is used for both the VACUUM command and for autovacuum. There
were many prechecks being done inside vacuum() that were just not relevant
to autovacuum.  Let's move the bulk of these into ExecVacuum() so that
they're only executed when running the VACUUM command.  This removes a
small amount of overhead when autovacuum vacuums a table.

While we are at it, allocate VACUUM's BufferAccessStrategy in ExecVacuum()
and pass it into vacuum() instead of expecting vacuum() to make it if it's
not already made by the calling function.  To make this work, we need to
create the vacuum memory context slightly earlier, so we now need to pass
that down to vacuum() so that it's available for use in other memory
allocations.

Author: Melanie Plageman
Reviewed-by: David Rowley
Discussion: https://postgr.es/m/20230405211534.4skgskbilnxqrmxg@awork3.anarazel.de
This commit is contained in:
David Rowley
2023-04-06 15:44:52 +12:00
parent acab1b0914
commit b9b125b9c1
3 changed files with 91 additions and 78 deletions

View File

@@ -3140,6 +3140,9 @@ relation_needs_vacanalyze(Oid relid,
/*
* autovacuum_do_vac_analyze
* Vacuum and/or analyze the specified table
*
* We expect the caller to have switched into a memory context that won't
* disappear at transaction commit.
*/
static void
autovacuum_do_vac_analyze(autovac_table *tab, BufferAccessStrategy bstrategy)
@@ -3147,6 +3150,7 @@ autovacuum_do_vac_analyze(autovac_table *tab, BufferAccessStrategy bstrategy)
RangeVar *rangevar;
VacuumRelation *rel;
List *rel_list;
MemoryContext vac_context;
/* Let pgstat know what we're doing */
autovac_report_activity(tab);
@@ -3156,7 +3160,13 @@ autovacuum_do_vac_analyze(autovac_table *tab, BufferAccessStrategy bstrategy)
rel = makeVacuumRelation(rangevar, tab->at_relid, NIL);
rel_list = list_make1(rel);
vacuum(rel_list, &tab->at_params, bstrategy, true);
vac_context = AllocSetContextCreate(CurrentMemoryContext,
"Vacuum",
ALLOCSET_DEFAULT_SIZES);
vacuum(rel_list, &tab->at_params, bstrategy, vac_context, true);
MemoryContextDelete(vac_context);
}
/*