Add a function to update the new pg_class cols
authorCédric Villemain <cedric@2ndquadrant.fr>
Sun, 1 May 2011 13:52:32 +0000 (15:52 +0200)
committerCédric Villemain <cedric@2ndquadrant.fr>
Sun, 1 May 2011 13:52:32 +0000 (15:52 +0200)
function is a copy of vac_update_relstats() but
just updating the columns relative to cache
statistics

src/backend/commands/vacuum.c
src/include/commands/vacuum.h

index 9606569617afafe16c55752183cb2a6de89bcad1..b45f012f9c0f224dc5e2e6031122b5d027240779 100644 (file)
@@ -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);
+}
index 79c9f5d90fb674ca8c778a65ca540ef62bded0af..7f1801ab3570666731dac0378b5ba8d727f63a19 100644 (file)
@@ -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);