From 1e2dffd1007d488b5848ee7b5fa0016914cc1b60 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Villemain?= <cedric@2ndquadrant.fr>
Date: Wed, 25 May 2011 23:43:27 +0200
Subject: [PATCH 2/7] Add a function to update the new pg_class cols

function is a copy of vac_update_relstats() but
just updating the oscache_percent column
---
 src/backend/commands/vacuum.c |   42 +++++++++++++++++++++++++++++++++++++++++
 src/include/commands/vacuum.h |    4 +++
 2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
new file mode 100644
index 5cbf3a0..ba1f7bb
*** a/src/backend/commands/vacuum.c
--- b/src/backend/commands/vacuum.c
*************** vacuum_delay_point(void)
*** 1162,1164 ****
--- 1162,1206 ----
  		CHECK_FOR_INTERRUPTS();
  	}
  }
+ 
+ 
+ /*
+  *	oscache_update_relstats() -- update oscache statistics for one relation
+  *
+  *  /!\ Same comment as function vac_update_relstats()
+  */
+ void
+ oscache_update_relstats(Relation relation,
+ 						float4 per_oscache,
+ 						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 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
new file mode 100644
index cfbe0c4..5bceec0
*** a/src/include/commands/vacuum.h
--- b/src/include/commands/vacuum.h
*************** extern void vacuum_set_xid_limits(int fr
*** 159,164 ****
--- 159,168 ----
  extern void vac_update_datfrozenxid(void);
  extern void vacuum_delay_point(void);
  
+ extern void oscache_update_relstats(Relation relation,
+ 									float4 per_oscache,
+ 									TransactionId frozenxid);
+ 
  /* in commands/vacuumlazy.c */
  extern void lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
  				BufferAccessStrategy bstrategy);
-- 
1.7.5.3

