Skip to content

Commit 6287eb7

Browse files
committed
Separate fetch of pg_autovacuum tuple into its own function.
1 parent 8aaecaf commit 6287eb7

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

src/backend/postmaster/autovacuum.c

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.35 2007/03/23 20:56:39 alvherre Exp $
13+
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.36 2007/03/23 21:23:13 alvherre Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -127,6 +127,7 @@ static void test_rel_for_autovac(Oid relid, PgStat_StatTabEntry *tabentry,
127127
List **toast_table_ids);
128128
static void autovacuum_do_vac_analyze(Oid relid, bool dovacuum,
129129
bool doanalyze, int freeze_min_age);
130+
static HeapTuple get_pg_autovacuum_tuple_relid(Relation avRel, Oid relid);
130131
static void autovac_report_activity(VacuumStmt *vacstmt, Oid relid);
131132
static void avl_sighup_handler(SIGNAL_ARGS);
132133
static void avlauncher_shutdown(SIGNAL_ARGS);
@@ -933,9 +934,7 @@ do_autovacuum(PgStat_StatDBEntry *dbentry)
933934
Form_pg_class classForm = (Form_pg_class) GETSTRUCT(tuple);
934935
Form_pg_autovacuum avForm = NULL;
935936
PgStat_StatTabEntry *tabentry;
936-
SysScanDesc avScan;
937937
HeapTuple avTup;
938-
ScanKeyData entry[1];
939938
Oid relid;
940939

941940
/* Consider only regular and toast tables. */
@@ -952,16 +951,8 @@ do_autovacuum(PgStat_StatDBEntry *dbentry)
952951

953952
relid = HeapTupleGetOid(tuple);
954953

955-
/* See if we have a pg_autovacuum entry for this relation. */
956-
ScanKeyInit(&entry[0],
957-
Anum_pg_autovacuum_vacrelid,
958-
BTEqualStrategyNumber, F_OIDEQ,
959-
ObjectIdGetDatum(relid));
960-
961-
avScan = systable_beginscan(avRel, AutovacuumRelidIndexId, true,
962-
SnapshotNow, 1, entry);
963-
964-
avTup = systable_getnext(avScan);
954+
/* Fetch the pg_autovacuum tuple for the relation, if any */
955+
avTup = get_pg_autovacuum_tuple_relid(avRel, relid);
965956

966957
if (HeapTupleIsValid(avTup))
967958
avForm = (Form_pg_autovacuum) GETSTRUCT(avTup);
@@ -978,7 +969,8 @@ do_autovacuum(PgStat_StatDBEntry *dbentry)
978969
test_rel_for_autovac(relid, tabentry, classForm, avForm,
979970
&vacuum_tables, &toast_table_ids);
980971

981-
systable_endscan(avScan);
972+
if (HeapTupleIsValid(avTup))
973+
heap_freetuple(avTup);
982974
}
983975

984976
heap_endscan(relScan);
@@ -1030,6 +1022,35 @@ do_autovacuum(PgStat_StatDBEntry *dbentry)
10301022
CommitTransactionCommand();
10311023
}
10321024

1025+
/*
1026+
* Returns a copy of the pg_autovacuum tuple for the given relid, or NULL if
1027+
* there isn't any. avRel is pg_autovacuum, already open and suitably locked.
1028+
*/
1029+
static HeapTuple
1030+
get_pg_autovacuum_tuple_relid(Relation avRel, Oid relid)
1031+
{
1032+
ScanKeyData entry[1];
1033+
SysScanDesc avScan;
1034+
HeapTuple avTup;
1035+
1036+
ScanKeyInit(&entry[0],
1037+
Anum_pg_autovacuum_vacrelid,
1038+
BTEqualStrategyNumber, F_OIDEQ,
1039+
ObjectIdGetDatum(relid));
1040+
1041+
avScan = systable_beginscan(avRel, AutovacuumRelidIndexId, true,
1042+
SnapshotNow, 1, entry);
1043+
1044+
avTup = systable_getnext(avScan);
1045+
1046+
if (HeapTupleIsValid(avTup))
1047+
avTup = heap_copytuple(avTup);
1048+
1049+
systable_endscan(avScan);
1050+
1051+
return avTup;
1052+
}
1053+
10331054
/*
10341055
* test_rel_for_autovac
10351056
*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy