summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Villemain2011-05-01 13:52:32 +0000
committerCédric Villemain2011-05-01 13:52:32 +0000
commit23621f75f0d5696a10996275ac986ecc4335dabb (patch)
tree5dca318ba7e56ba3ab4b8152bcd15b8297de75a8
parent4d428b46015525b162dd6dc4e37c82e5ab423e14 (diff)
Add a function to update the new pg_class cols
function is a copy of vac_update_relstats() but just updating the columns relative to cache statistics
-rw-r--r--src/backend/commands/vacuum.c58
-rw-r--r--src/include/commands/vacuum.h5
2 files changed, 63 insertions, 0 deletions
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index 9606569617..b45f012f9c 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -1096,3 +1096,61 @@ vacuum_delay_point(void)
CHECK_FOR_INTERRUPTS();
}
}
+
+
+/*
+ * cache_update_relstats() -- update cache statistics for one relation
+ *
+ * /!\ Same comment as function vac_update_relstats()
+ */
+void
+cache_update_relstats(Relation relation,
+ float4 per_oscache, float4 per_pgcache,
+ TransactionId frozenxid)
+{
+ Oid relid = RelationGetRelid(relation);
+ Relation rd;
+ HeapTuple ctup;
+ Form_pg_class pgcform;
+ bool dirty;
+
+ rd = heap_open(RelationRelationId, RowExclusiveLock);
+
+ /* Fetch a copy of the tuple to scribble on */
+ ctup = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(relid));
+ if (!HeapTupleIsValid(ctup))
+ elog(ERROR, "pg_class entry for relid %u vanished during cache analyze",
+ relid);
+ pgcform = (Form_pg_class) GETSTRUCT(ctup);
+
+ /* Apply required updates, if any, to copied tuple */
+
+ dirty = false;
+ if (pgcform->reloscache != (float4) per_oscache)
+ {
+ pgcform->reloscache = (float4) per_oscache;
+ dirty = true;
+ }
+ if (pgcform->relpgcache != (float4) per_pgcache)
+ {
+ pgcform->relpgcache = (float4) per_pgcache;
+ dirty = true;
+ }
+
+ /*
+ * relfrozenxid should never go backward. Caller can pass
+ * InvalidTransactionId if it has no new data.
+ */
+ if (TransactionIdIsNormal(frozenxid) &&
+ TransactionIdPrecedes(pgcform->relfrozenxid, frozenxid))
+ {
+ pgcform->relfrozenxid = frozenxid;
+ dirty = true;
+ }
+
+ /* If anything changed, write out the tuple. */
+ if (dirty)
+ heap_inplace_update(rd, ctup);
+
+ heap_close(rd, RowExclusiveLock);
+}
diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h
index 79c9f5d90f..7f1801ab35 100644
--- a/src/include/commands/vacuum.h
+++ b/src/include/commands/vacuum.h
@@ -155,6 +155,11 @@ extern void vacuum_set_xid_limits(int freeze_min_age, int freeze_table_age,
extern void vac_update_datfrozenxid(void);
extern void vacuum_delay_point(void);
+extern void cache_update_relstats(Relation relation,
+ float4 per_oscache,
+ float4 per_pgcache,
+ TransactionId frozenxid);
+
/* in commands/vacuumlazy.c */
extern void lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
BufferAccessStrategy bstrategy, bool *scanned_all);