diff options
Diffstat (limited to 'src/backend/utils/cache')
| -rw-r--r-- | src/backend/utils/cache/catcache.c | 24 | ||||
| -rw-r--r-- | src/backend/utils/cache/relcache.c | 36 |
2 files changed, 28 insertions, 32 deletions
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c index f843f2bb16..cd54ff7665 100644 --- a/src/backend/utils/cache/catcache.c +++ b/src/backend/utils/cache/catcache.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.77 2001/03/22 03:59:55 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.78 2001/06/01 02:41:36 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -205,7 +205,6 @@ CatalogCacheInitializeCache(CatCache *cache) /* * switch to the cache context so our allocations do not vanish at the * end of a transaction - * */ if (!CacheMemoryContext) CreateCacheMemoryContext(); @@ -214,13 +213,11 @@ CatalogCacheInitializeCache(CatCache *cache) /* * copy the relcache's tuple descriptor to permanent cache storage - * */ tupdesc = CreateTupleDescCopyConstr(RelationGetDescr(relation)); /* * return to the caller's memory context and close the rel - * */ MemoryContextSwitchTo(oldcxt); @@ -231,7 +228,6 @@ CatalogCacheInitializeCache(CatCache *cache) /* * initialize cache's key information - * */ for (i = 0; i < cache->cc_nkeys; ++i) { @@ -255,9 +251,23 @@ CatalogCacheInitializeCache(CatCache *cache) */ cache->cc_skey[i].sk_procedure = EQPROC(keytype); + /* + * Note: to avoid any possible leakage of scan temporary data into + * the cache context, we do not switch into CacheMemoryContext while + * calling fmgr_info here. Instead set fn_mcxt on return. This + * would fail to work correctly if fmgr_info allocated any subsidiary + * data structures to attach to the FmgrInfo record; but it doesn't + * do so for built-in functions, and all the comparator functions + * for system caches should most assuredly be built-in functions. + * Currently there's no real need to fix fn_mcxt either, but let's do + * that anyway just to make sure it's not pointing to a dead context + * later on. + */ + fmgr_info(cache->cc_skey[i].sk_procedure, &cache->cc_skey[i].sk_func); - cache->cc_skey[i].sk_nargs = cache->cc_skey[i].sk_func.fn_nargs; + + cache->cc_skey[i].sk_func.fn_mcxt = CacheMemoryContext; /* Initialize sk_attno suitably for HeapKeyTest() and heap scans */ cache->cc_skey[i].sk_attno = cache->cc_key[i]; @@ -270,7 +280,6 @@ CatalogCacheInitializeCache(CatCache *cache) /* * mark this cache fully initialized - * */ cache->cc_tupdesc = tupdesc; } @@ -705,7 +714,6 @@ InitCatCache(int id, * certain system indexes that support critical syscaches. * We can't use an indexscan to fetch these, else we'll get into * infinite recursion. A plain heap scan will work, however. - * */ static bool IndexScanOK(CatCache *cache, ScanKey cur_skey) diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index d04e0cd559..6431bd9382 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.135 2001/05/30 14:15:26 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.136 2001/06/01 02:41:36 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1161,19 +1161,20 @@ IndexedAccessMethodInitialize(Relation relation) int natts; Size stratSize; Size supportSize; - uint16 relamstrategies; - uint16 relamsupport; + uint16 amstrategies; + uint16 amsupport; natts = relation->rd_rel->relnatts; - relamstrategies = relation->rd_am->amstrategies; - stratSize = AttributeNumberGetIndexStrategySize(natts, relamstrategies); + amstrategies = relation->rd_am->amstrategies; + amsupport = relation->rd_am->amsupport; + + stratSize = AttributeNumberGetIndexStrategySize(natts, amstrategies); strategy = (IndexStrategy) MemoryContextAlloc(CacheMemoryContext, stratSize); - relamsupport = relation->rd_am->amsupport; - if (relamsupport > 0) + if (amsupport > 0) { - supportSize = natts * (relamsupport * sizeof(RegProcedure)); + supportSize = natts * (amsupport * sizeof(RegProcedure)); support = (RegProcedure *) MemoryContextAlloc(CacheMemoryContext, supportSize); } @@ -1182,9 +1183,9 @@ IndexedAccessMethodInitialize(Relation relation) IndexSupportInitialize(strategy, support, &relation->rd_uniqueindex, - relation->rd_att->attrs[0]->attrelid, + RelationGetRelid(relation), relation->rd_rel->relam, - relamstrategies, relamsupport, natts); + amstrategies, amsupport, natts); RelationSetIndexSupport(relation, strategy, support); } @@ -1212,26 +1213,22 @@ formrdesc(char *relationName, /* * allocate new relation desc - * */ relation = (Relation) palloc(sizeof(RelationData)); MemSet((char *) relation, 0, sizeof(RelationData)); /* * don't open the unix file yet.. - * */ relation->rd_fd = -1; /* * initialize reference count - * */ RelationSetReferenceCount(relation, 1); /* * all entries built with this routine are nailed-in-cache - * */ relation->rd_isnailed = true; @@ -1241,7 +1238,6 @@ formrdesc(char *relationName, * The data we insert here is pretty incomplete/bogus, but it'll serve to * get us launched. RelationCacheInitializePhase2() will read the * real data from pg_class and replace what we've done here. - * */ relation->rd_rel = (Form_pg_class) palloc(CLASS_TUPLE_SIZE); MemSet(relation->rd_rel, 0, CLASS_TUPLE_SIZE); @@ -1266,13 +1262,11 @@ formrdesc(char *relationName, /* * initialize attribute tuple form - * */ relation->rd_att = CreateTemplateTupleDesc(natts); /* * initialize tuple desc info - * */ for (i = 0; i < natts; i++) { @@ -1283,14 +1277,12 @@ formrdesc(char *relationName, } /* - * initialize relation id - * + * initialize relation id from info in att array (my, this is ugly) */ RelationGetRelid(relation) = relation->rd_att->attrs[0]->attrelid; /* * initialize the relation's lock manager and RelFileNode information - * */ RelationInitLockInfo(relation); /* see lmgr.c */ @@ -1303,7 +1295,6 @@ formrdesc(char *relationName, /* * initialize the rel-has-index flag, using hardwired knowledge - * */ relation->rd_rel->relhasindex = false; @@ -1322,7 +1313,6 @@ formrdesc(char *relationName, /* * add new reldesc to relcache - * */ RelationCacheInsert(relation); } @@ -2755,10 +2745,8 @@ init_irels(void) { fmgr_info(SMD(i).sk_procedure, &(SMD(i).sk_func)); - SMD(i).sk_nargs = SMD(i).sk_func.fn_nargs; } - /* * use a real field called rd_istrat instead of the bogosity of * hanging invisible fields off the end of a structure - jolly |
