Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6c7c6d0

Browse files
committed
From: Jan Wieck <jwieck@debis.com>
The diff looks so simple and easy. But to find it wasn't fun. It must have been there for a long time. What happened: When a tuple in one of some central catalogs was updated, the referenced relation got flushed, so it would be reopened on the next access (to reflect new triggers, rules and table structure changes into the relation cache). Some data (the tupleDescriptor e.g.) is used in the system cache too. So when a relation is subject to the system cache, this must know too that a cached system relation got flushed because the tupleDesc data gets freed during the flush! For the GRANT/REVOKE on pg_class it was slightly different. There is some local data in inval.c that gets initialized on the first invalidation of a tuple in some central catalogs. This needs a SysCache lookup in pg_class. But when the first of all commands is a GRANT on pg_class, exactly the needed tuple is the one actually invalidated. So I added little code snippets that the initialization of the local variables in inval.c will already happen during InitPostgres().
1 parent9324d5c commit6c7c6d0

File tree

6 files changed

+55
-6
lines changed

6 files changed

+55
-6
lines changed

‎src/backend/utils/cache/catcache.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.22 1998/02/11 19:12:47 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.23 1998/02/23 17:43:19 scrappy Exp $
1111
*
1212
* Notes:
1313
*XXX This needs to use exception.h to handle recovery when
@@ -620,6 +620,29 @@ ResetSystemCache()
620620
MemoryContextSwitchTo(oldcxt);
621621
}
622622

623+
/* --------------------------------
624+
*SystemCacheRelationFlushed
625+
*
626+
*RelationFlushRelation() frees some information referenced in the
627+
*cache structures. So we get informed when this is done and arrange
628+
*for the next SearchSysCache() call that this information is setup
629+
*again.
630+
* --------------------------------
631+
*/
632+
void
633+
SystemCacheRelationFlushed(OidrelId)
634+
{
635+
structcatcache*cache;
636+
637+
for (cache=Caches;PointerIsValid(cache);cache=cache->cc_next)
638+
{
639+
if (cache->relationId==relId)
640+
{
641+
cache->relationId=InvalidOid;
642+
}
643+
}
644+
}
645+
623646
/* --------------------------------
624647
*InitIndexedSysCache
625648
*

‎src/backend/utils/cache/inval.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.9 1997/11/17 16:59:22 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.10 1998/02/23 17:43:23 scrappy Exp $
1111
*
1212
* Note - this code is real crufty...
1313
*
@@ -512,6 +512,20 @@ RelationInvalidateRelationCache(Relation relation,
512512
(*function) (relationId,objectId);
513513
}
514514

515+
516+
/*
517+
*InitLocalInvalidateData
518+
*
519+
*Setup this before anything could ever get invalid!
520+
*Called by InitPostgres();
521+
*/
522+
void
523+
InitLocalInvalidateData()
524+
{
525+
ValidateHacks();
526+
}
527+
528+
515529
/*
516530
* DiscardInvalid --
517531
*Causes the invalidated cache state to be discarded.

‎src/backend/utils/cache/relcache.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.35 1998/01/31 04:38:52 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.36 1998/02/23 17:43:25 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -65,6 +65,7 @@
6565
#include"utils/relcache.h"
6666
#include"utils/hsearch.h"
6767
#include"utils/relcache.h"
68+
#include"utils/catcache.h"
6869

6970
#include"catalog/catname.h"
7071
#include"catalog/catalog.h"
@@ -1344,6 +1345,7 @@ RelationFlushRelation(Relation *relationPtr,
13441345
RelationCacheDelete(relation);
13451346

13461347
FreeTupleDesc(relation->rd_att);
1348+
SystemCacheRelationFlushed(relation->rd_id);
13471349

13481350
FreeTriggerDesc(relation);
13491351

‎src/backend/utils/init/postinit.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.22 1998/01/29 03:23:28 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.23 1998/02/23 17:43:53 scrappy Exp $
1111
*
1212
* NOTES
1313
*InitPostgres() is the function called from PostgresMain
@@ -62,6 +62,7 @@
6262
#include"utils/elog.h"
6363
#include"utils/palloc.h"
6464
#include"utils/mcxt.h"/* for EnableMemoryContext, etc. */
65+
#include"utils/inval.h"
6566

6667
#include"catalog/catname.h"
6768
#include"catalog/pg_database.h"
@@ -586,6 +587,12 @@ InitPostgres(char *name)/* database name */
586587
*/
587588
InitUserid();
588589

590+
/* ----------------
591+
* initialize local data in cache invalidation stuff
592+
* ----------------
593+
*/
594+
InitLocalInvalidateData();
595+
589596
/* ----------------
590597
*ok, all done, now let's make sure we don't do it again.
591598
* ----------------

‎src/include/utils/catcache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: catcache.h,v 1.9 1998/01/24 22:50:34 momjian Exp $
9+
* $Id: catcache.h,v 1.10 1998/02/23 17:44:22 scrappy Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -66,6 +66,7 @@ extern GlobalMemory CacheCxt;
6666
externvoidCatalogCacheIdInvalidate(intcacheId,IndexhashIndex,
6767
ItemPointerpointer);
6868
externvoidResetSystemCache(void);
69+
externvoidSystemCacheRelationFlushed(OidrelId);
6970
externCatCache*InitSysCache(char*relname,char*indname,intid,intnkeys,
7071
intkey[],HeapTuple (*iScanfuncP) ());
7172
externHeapTupleSearchSysCache(structcatcache*cache,Datumv1,Datumv2,

‎src/include/utils/inval.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: inval.h,v 1.7 1997/09/08 21:55:08 momjian Exp $
9+
* $Id: inval.h,v 1.8 1998/02/23 17:44:24 scrappy Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -16,6 +16,8 @@
1616
#include<access/htup.h>
1717
#include<utils/rel.h>
1818

19+
externvoidInitLocalInvalidateData(void);
20+
1921
externvoidDiscardInvalid(void);
2022

2123
externvoidRegisterInvalid(boolsend);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp