mirror of
https://github.com/postgres/postgres.git
synced 2025-08-27 07:42:10 +03:00
Fix SysCacheGetAttr() to handle the case where the specified syscache has not
been initialized yet. This can happen because there are code paths that call SysCacheGetAttr() on a tuple originally fetched from a different syscache (hopefully on the same catalog) than the one specified in the call. It doesn't seem useful or robust to try to prevent that from happening, so just improve the function to cope instead. Per bug#2678 from Jeff Trout. The specific example shown by Jeff is new in 8.1, but to be on the safe side I'm backpatching 8.0 as well. We could patch 7.x similarly but I think that's probably overkill, given the lack of evidence of old bugs of this ilk.
This commit is contained in:
18
src/backend/utils/cache/catcache.c
vendored
18
src/backend/utils/cache/catcache.c
vendored
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/cache/catcache.c,v 1.133 2006/10/04 00:30:00 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/cache/catcache.c,v 1.134 2006/10/06 18:23:35 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -976,7 +976,7 @@ CatalogCacheInitializeCache(CatCache *cache)
|
||||
cache->cc_skey[i].sk_strategy = BTEqualStrategyNumber;
|
||||
cache->cc_skey[i].sk_subtype = InvalidOid;
|
||||
|
||||
CACHE4_elog(DEBUG2, "CatalogCacheInit %s %d %p",
|
||||
CACHE4_elog(DEBUG2, "CatalogCacheInitializeCache %s %d %p",
|
||||
cache->cc_relname,
|
||||
i,
|
||||
cache);
|
||||
@@ -991,18 +991,20 @@ CatalogCacheInitializeCache(CatCache *cache)
|
||||
/*
|
||||
* InitCatCachePhase2 -- external interface for CatalogCacheInitializeCache
|
||||
*
|
||||
* The only reason to call this routine is to ensure that the relcache
|
||||
* has created entries for all the catalogs and indexes referenced by
|
||||
* catcaches. Therefore, open the index too. An exception is the indexes
|
||||
* on pg_am, which we don't use (cf. IndexScanOK).
|
||||
* One reason to call this routine is to ensure that the relcache has
|
||||
* created entries for all the catalogs and indexes referenced by catcaches.
|
||||
* Therefore, provide an option to open the index as well as fixing the
|
||||
* cache itself. An exception is the indexes on pg_am, which we don't use
|
||||
* (cf. IndexScanOK).
|
||||
*/
|
||||
void
|
||||
InitCatCachePhase2(CatCache *cache)
|
||||
InitCatCachePhase2(CatCache *cache, bool touch_index)
|
||||
{
|
||||
if (cache->cc_tupdesc == NULL)
|
||||
CatalogCacheInitializeCache(cache);
|
||||
|
||||
if (cache->id != AMOID &&
|
||||
if (touch_index &&
|
||||
cache->id != AMOID &&
|
||||
cache->id != AMNAME)
|
||||
{
|
||||
Relation idesc;
|
||||
|
Reference in New Issue
Block a user