From e44beef712144316cb83d32ccf3231a1503c9655 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 11 Aug 2002 21:17:35 +0000 Subject: Code review of CLUSTER patch. Clean up problems with relcache getting confused, toasted data getting lost, etc. --- src/backend/storage/buffer/bufmgr.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/backend/storage/buffer/bufmgr.c') diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 1ca7af3b77..11df91c25c 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.128 2002/08/06 02:36:34 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.129 2002/08/11 21:17:34 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1038,11 +1038,6 @@ BufferReplace(BufferDesc *bufHdr) * RelationGetNumberOfBlocks * Determines the current number of pages in the relation. * Side effect: relation->rd_nblocks is updated. - * - * Note: - * XXX may fail for huge relations. - * XXX should be elsewhere. - * XXX maybe should be hidden */ BlockNumber RelationGetNumberOfBlocks(Relation relation) @@ -1061,6 +1056,23 @@ RelationGetNumberOfBlocks(Relation relation) return relation->rd_nblocks; } +/* + * RelationUpdateNumberOfBlocks + * Forcibly update relation->rd_nblocks. + * + * If the relcache drops an entry for a temp relation, it must call this + * routine after recreating the relcache entry, so that rd_nblocks is + * re-sync'd with reality. See RelationGetNumberOfBlocks. + */ +void +RelationUpdateNumberOfBlocks(Relation relation) +{ + if (relation->rd_rel->relkind == RELKIND_VIEW) + relation->rd_nblocks = 0; + else + relation->rd_nblocks = smgrnblocks(DEFAULT_SMGR, relation); +} + /* --------------------------------------------------------------------- * DropRelationBuffers * -- cgit v1.2.1