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

Commit6ea8f49

Browse files
committed
Fix SysCacheGetAttr() to handle the case where the specified syscache has not
been initialized yet. This can happen because there are code paths that callSysCacheGetAttr() on a tuple originally fetched from a different syscache(hopefully on the same catalog) than the one specified in the call. Itdoesn't seem useful or robust to try to prevent that from happening, so justimprove the function to cope instead. Per bug#2678 from Jeff Trout. Thespecific example shown by Jeff is new in 8.1, but to be on the safe sideI'm backpatching 8.0 as well. We could patch 7.x similarly but I thinkthat's probably overkill, given the lack of evidence of old bugs of this ilk.
1 parentb9b4f10 commit6ea8f49

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/cache/catcache.c,v 1.133 2006/10/04 00:30:00 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/cache/catcache.c,v 1.134 2006/10/06 18:23:35 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -976,7 +976,7 @@ CatalogCacheInitializeCache(CatCache *cache)
976976
cache->cc_skey[i].sk_strategy=BTEqualStrategyNumber;
977977
cache->cc_skey[i].sk_subtype=InvalidOid;
978978

979-
CACHE4_elog(DEBUG2,"CatalogCacheInit %s %d %p",
979+
CACHE4_elog(DEBUG2,"CatalogCacheInitializeCache %s %d %p",
980980
cache->cc_relname,
981981
i,
982982
cache);
@@ -991,18 +991,20 @@ CatalogCacheInitializeCache(CatCache *cache)
991991
/*
992992
* InitCatCachePhase2 -- external interface for CatalogCacheInitializeCache
993993
*
994-
* The only reason to call this routine is to ensure that the relcache
995-
* has created entries for all the catalogs and indexes referenced by
996-
* catcaches. Therefore, open the index too. An exception is the indexes
997-
* on pg_am, which we don't use (cf. IndexScanOK).
994+
* One reason to call this routine is to ensure that the relcache has
995+
* created entries for all the catalogs and indexes referenced by catcaches.
996+
* Therefore, provide an option to open the index as well as fixing the
997+
* cache itself. An exception is the indexes on pg_am, which we don't use
998+
* (cf. IndexScanOK).
998999
*/
9991000
void
1000-
InitCatCachePhase2(CatCache*cache)
1001+
InitCatCachePhase2(CatCache*cache,booltouch_index)
10011002
{
10021003
if (cache->cc_tupdesc==NULL)
10031004
CatalogCacheInitializeCache(cache);
10041005

1005-
if (cache->id!=AMOID&&
1006+
if (touch_index&&
1007+
cache->id!=AMOID&&
10061008
cache->id!=AMNAME)
10071009
{
10081010
Relationidesc;

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/cache/syscache.c,v 1.107 2006/10/04 00:30:00 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/cache/syscache.c,v 1.108 2006/10/06 18:23:35 tgl Exp $
1212
*
1313
* NOTES
1414
* These routines allow the parser/planner/executor to perform
@@ -576,7 +576,7 @@ InitCatalogCachePhase2(void)
576576
Assert(CacheInitialized);
577577

578578
for (cacheId=0;cacheId<SysCacheSize;cacheId++)
579-
InitCatCachePhase2(SysCache[cacheId]);
579+
InitCatCachePhase2(SysCache[cacheId], true);
580580
}
581581

582582

@@ -773,6 +773,9 @@ SearchSysCacheExistsAttName(Oid relid, const char *attname)
773773
* As with heap_getattr(), if the attribute is of a pass-by-reference type
774774
* then a pointer into the tuple data area is returned --- the caller must
775775
* not modify or pfree the datum!
776+
*
777+
* Note: it is legal to use SysCacheGetAttr() with a cacheId referencing
778+
* a different cache for the same catalog the tuple was fetched from.
776779
*/
777780
Datum
778781
SysCacheGetAttr(intcacheId,HeapTupletup,
@@ -781,15 +784,18 @@ SysCacheGetAttr(int cacheId, HeapTuple tup,
781784
{
782785
/*
783786
* We just need to get the TupleDesc out of the cache entry, and then we
784-
* can apply heap_getattr().We expect thatthe cache control data is
785-
*currentlyvalid--- ifthe caller recently fetched the tuple, then it
786-
*should be.
787+
* can apply heap_getattr().Normallythe cache control data is already
788+
* valid(becausethe caller recently fetched the tuple via this same
789+
*cache), but there are cases where we have to initialize the cache here.
787790
*/
788-
if (cacheId<0||cacheId >=SysCacheSize)
791+
if (cacheId<0||cacheId >=SysCacheSize||
792+
!PointerIsValid(SysCache[cacheId]))
789793
elog(ERROR,"invalid cache id: %d",cacheId);
790-
if (!PointerIsValid(SysCache[cacheId])||
791-
!PointerIsValid(SysCache[cacheId]->cc_tupdesc))
792-
elog(ERROR,"missing cache data for cache id %d",cacheId);
794+
if (!PointerIsValid(SysCache[cacheId]->cc_tupdesc))
795+
{
796+
InitCatCachePhase2(SysCache[cacheId], false);
797+
Assert(PointerIsValid(SysCache[cacheId]->cc_tupdesc));
798+
}
793799

794800
returnheap_getattr(tup,attributeNumber,
795801
SysCache[cacheId]->cc_tupdesc,

‎src/include/utils/catcache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
16-
* $PostgreSQL: pgsql/src/include/utils/catcache.h,v 1.62 2006/10/04 00:30:10 momjian Exp $
16+
* $PostgreSQL: pgsql/src/include/utils/catcache.h,v 1.63 2006/10/06 18:23:35 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -166,7 +166,7 @@ extern CatCache *InitCatCache(int id, Oid reloid, Oid indexoid,
166166
intreloidattr,
167167
intnkeys,constint*key,
168168
intnbuckets);
169-
externvoidInitCatCachePhase2(CatCache*cache);
169+
externvoidInitCatCachePhase2(CatCache*cache,booltouch_index);
170170

171171
externHeapTupleSearchCatCache(CatCache*cache,
172172
Datumv1,Datumv2,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp