diff options
Diffstat (limited to 'src/backend/commands/vacuum.c')
-rw-r--r-- | src/backend/commands/vacuum.c | 58 |
1 files changed, 58 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); +} |