Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
07dfe977
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
07dfe977
编写于
7月 02, 2000
作者:
T
Tom Lane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't run in CacheMemoryContext more than necessary.
上级
d0032132
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
34 addition
and
150 deletion
+34
-150
src/backend/utils/cache/catcache.c
src/backend/utils/cache/catcache.c
+34
-150
未找到文件。
src/backend/utils/cache/catcache.c
浏览文件 @
07dfe977
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.6
8 2000/06/28 03:32:24
tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.6
9 2000/07/02 05:38:40
tgl Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -190,57 +190,32 @@ CatalogCacheInitializeCache(CatCache * cache,
Relation
relation
)
{
MemoryContext
oldcxt
;
short
didopen
=
0
;
bool
didopen
=
false
;
short
i
;
TupleDesc
tupdesc
;
CatalogCacheInitializeCache_DEBUG1
;
/* ----------------
* first switch to the cache context so our allocations
* do not vanish at the end of a transaction
* ----------------
*/
if
(
!
CacheMemoryContext
)
CreateCacheMemoryContext
();
oldcxt
=
MemoryContextSwitchTo
(
CacheMemoryContext
);
/* ----------------
* If no relation was passed we must open it to get access to
* its fields. If one of the other caches has already opened
* it we use heap_open() instead of heap_openr().
* XXX is that really worth the trouble of checking?
* its fields.
* ----------------
*/
if
(
!
RelationIsValid
(
relation
))
{
CatCache
*
cp
;
/* ----------------
* scan the caches to see if any other cache has opened the relation
* ----------------
*/
for
(
cp
=
Caches
;
cp
;
cp
=
cp
->
cc_next
)
{
if
(
strncmp
(
cp
->
cc_relname
,
cache
->
cc_relname
,
NAMEDATALEN
)
==
0
)
{
if
(
cp
->
relationId
!=
InvalidOid
)
break
;
}
relation
=
heap_openr
(
cache
->
cc_relname
,
NoLock
);
didopen
=
true
;
}
/* ----------------
* open the relation by name or by id
* switch to the cache context so our allocations
* do not vanish at the end of a transaction
* ----------------
*/
if
(
cp
)
relation
=
heap_open
(
cp
->
relationId
,
NoLock
);
else
relation
=
heap_openr
(
cache
->
cc_relname
,
NoLock
);
if
(
!
CacheMemoryContext
)
CreateCacheMemoryContext
();
didopen
=
1
;
}
oldcxt
=
MemoryContextSwitchTo
(
CacheMemoryContext
);
/* ----------------
* initialize the cache's relation id and tuple descriptor
...
...
@@ -285,6 +260,12 @@ CatalogCacheInitializeCache(CatCache * cache,
}
}
/* ----------------
* return to the caller's memory context
* ----------------
*/
MemoryContextSwitchTo
(
oldcxt
);
/* ----------------
* close the relation if we opened it
* ----------------
...
...
@@ -313,12 +294,6 @@ CatalogCacheInitializeCache(CatCache * cache,
else
cache
->
cc_indname
=
NULL
;
}
/* ----------------
* return to the proper memory context
* ----------------
*/
MemoryContextSwitchTo
(
oldcxt
);
}
/* --------------------------------
...
...
@@ -433,8 +408,6 @@ CatalogCacheComputeTupleHashIndex(CatCache * cacheInOutP,
/* --------------------------------
* CatCacheRemoveCTup
*
* NB: assumes caller has switched to CacheMemoryContext
* --------------------------------
*/
static
void
...
...
@@ -482,7 +455,6 @@ CatalogCacheIdInvalidate(int cacheId, /* XXX */
CatCache
*
ccp
;
CatCTup
*
ct
;
Dlelem
*
elt
;
MemoryContext
oldcxt
;
/* ----------------
* sanity checks
...
...
@@ -492,15 +464,6 @@ CatalogCacheIdInvalidate(int cacheId, /* XXX */
Assert
(
ItemPointerIsValid
(
pointer
));
CACHE1_elog
(
DEBUG
,
"CatalogCacheIdInvalidate: called"
);
/* ----------------
* switch to the cache context for our memory allocations
* ----------------
*/
if
(
!
CacheMemoryContext
)
CreateCacheMemoryContext
();
oldcxt
=
MemoryContextSwitchTo
(
CacheMemoryContext
);
/* ----------------
* inspect every cache that could contain the tuple
* ----------------
...
...
@@ -537,12 +500,6 @@ CatalogCacheIdInvalidate(int cacheId, /* XXX */
if
(
cacheId
!=
InvalidCatalogCacheId
)
break
;
}
/* ----------------
* return to the proper memory context
* ----------------
*/
MemoryContextSwitchTo
(
oldcxt
);
}
/* ----------------------------------------------------------------
...
...
@@ -562,21 +519,10 @@ CatalogCacheIdInvalidate(int cacheId, /* XXX */
void
ResetSystemCache
()
{
MemoryContext
oldcxt
;
CatCache
*
cache
;
CACHE1_elog
(
DEBUG
,
"ResetSystemCache called"
);
/* ----------------
* first switch to the cache context so our allocations
* do not vanish at the end of a transaction
* ----------------
*/
if
(
!
CacheMemoryContext
)
CreateCacheMemoryContext
();
oldcxt
=
MemoryContextSwitchTo
(
CacheMemoryContext
);
/* ----------------
* here we purge the contents of all the caches
*
...
...
@@ -609,12 +555,6 @@ ResetSystemCache()
}
CACHE1_elog
(
DEBUG
,
"end of ResetSystemCache call"
);
/* ----------------
* back to the old context before we return...
* ----------------
*/
MemoryContextSwitchTo
(
oldcxt
);
}
/* --------------------------------
...
...
@@ -682,7 +622,7 @@ do { \
CatCache
*
InitSysCache
(
char
*
relname
,
char
*
iname
,
char
*
in
dn
ame
,
int
id
,
int
nkeys
,
int
*
key
,
...
...
@@ -692,10 +632,6 @@ InitSysCache(char *relname,
int
i
;
MemoryContext
oldcxt
;
char
*
indname
;
indname
=
(
iname
)
?
iname
:
NULL
;
/* ----------------
* first switch to the cache context so our allocations
* do not vanish at the end of a transaction
...
...
@@ -805,6 +741,7 @@ InitSysCache(char *relname,
* ----------------
*/
MemoryContextSwitchTo
(
oldcxt
);
return
cp
;
}
...
...
@@ -927,7 +864,7 @@ SearchSysCache(CatCache * cache,
CatCTup
*
nct
;
CatCTup
*
nct2
;
Dlelem
*
elt
;
HeapTuple
ntp
=
NULL
;
HeapTuple
ntp
;
Relation
relation
;
MemoryContext
oldcxt
;
...
...
@@ -950,7 +887,7 @@ SearchSysCache(CatCache * cache,
/*
* resolve self referencing informtion
*/
if
((
ntp
=
SearchSelfReferences
(
cache
)))
if
((
ntp
=
SearchSelfReferences
(
cache
))
!=
NULL
)
return
ntp
;
/* ----------------
...
...
@@ -1034,16 +971,6 @@ SearchSysCache(CatCache * cache,
CACHE2_elog
(
DEBUG
,
"SearchSysCache(%s)"
,
RelationGetRelationName
(
relation
));
/* ----------------
* Switch to the cache memory context.
* ----------------
*/
if
(
!
CacheMemoryContext
)
CreateCacheMemoryContext
();
oldcxt
=
MemoryContextSwitchTo
(
CacheMemoryContext
);
/* ----------------
* Scan the relation to find the tuple. If there's an index, and
* if this isn't bootstrap (initdb) time, use the index.
...
...
@@ -1056,14 +983,6 @@ SearchSysCache(CatCache * cache,
{
HeapTuple
indextp
;
/* ----------
* Switch back to old memory context so memory not freed
* in the scan function will go away at transaction end.
* wieck - 10/18/1996
* ----------
*/
MemoryContextSwitchTo
(
oldcxt
);
/* We call the scanfunc with all four arguments to satisfy the
* declared prototype, even though the function will likely not
* use all four.
...
...
@@ -1071,53 +990,39 @@ SearchSysCache(CatCache * cache,
indextp
=
cache
->
cc_iscanfunc
(
relation
,
v1
,
v2
,
v3
,
v4
);
/* ----------
* Back to Cache context. If we got a tuple copy it
* into our context. wieck - 10/18/1996
* If we got a tuple copy it into our context. wieck - 10/18/1996
* And free the tuple that was allocated in the
* transaction's context. tgl - 02/03/2000
* ----------
*/
if
(
HeapTupleIsValid
(
indextp
))
{
MemoryContextSwitchTo
(
CacheMemoryContext
);
oldcxt
=
MemoryContextSwitchTo
(
CacheMemoryContext
);
ntp
=
heap_copytuple
(
indextp
);
/* this switch is probably not needed anymore: */
MemoryContextSwitchTo
(
oldcxt
);
heap_freetuple
(
indextp
);
}
MemoryContextSwitchTo
(
CacheMemoryContext
);
}
else
{
HeapScanDesc
sd
;
/* ----------
* As above do the lookup in the callers memory
* context.
* wieck - 10/18/1996
* ----------
*/
MemoryContextSwitchTo
(
oldcxt
);
sd
=
heap_beginscan
(
relation
,
0
,
SnapshotNow
,
cache
->
cc_nkeys
,
cache
->
cc_skey
);
ntp
=
heap_getnext
(
sd
,
0
);
MemoryContextSwitchTo
(
CacheMemoryContext
);
if
(
HeapTupleIsValid
(
ntp
))
{
CACHE1_elog
(
DEBUG
,
"SearchSysCache: found tuple"
);
oldcxt
=
MemoryContextSwitchTo
(
CacheMemoryContext
);
ntp
=
heap_copytuple
(
ntp
);
MemoryContextSwitchTo
(
oldcxt
);
/* We should not free the result of heap_getnext... */
}
MemoryContextSwitchTo
(
oldcxt
);
heap_endscan
(
sd
);
MemoryContextSwitchTo
(
CacheMemoryContext
);
}
cache
->
busy
=
false
;
...
...
@@ -1136,6 +1041,8 @@ SearchSysCache(CatCache * cache,
*/
Dlelem
*
lru_elt
;
oldcxt
=
MemoryContextSwitchTo
(
CacheMemoryContext
);
/*
* this is a little cumbersome here because we want the Dlelem's
* in both doubly linked lists to point to one another. That makes
...
...
@@ -1154,6 +1061,8 @@ SearchSysCache(CatCache * cache,
DLAddHead
(
cache
->
cc_lrulist
,
lru_elt
);
DLAddHead
(
cache
->
cc_cache
[
hash
],
elt
);
MemoryContextSwitchTo
(
oldcxt
);
/* ----------------
* If we've exceeded the desired size of this cache,
* throw away the least recently used entry.
...
...
@@ -1183,14 +1092,11 @@ SearchSysCache(CatCache * cache,
}
/* ----------------
* close the relation, switch back to the original memory context
* and return the tuple we found (or NULL)
* close the relation and return the tuple we found (or NULL)
* ----------------
*/
heap_close
(
relation
,
AccessShareLock
);
MemoryContextSwitchTo
(
oldcxt
);
return
ntp
;
}
...
...
@@ -1209,7 +1115,6 @@ RelationInvalidateCatalogCacheTuple(Relation relation,
void
(
*
function
)
(
int
,
Index
,
ItemPointer
))
{
CatCache
*
ccp
;
MemoryContext
oldcxt
;
Oid
relationId
;
/* ----------------
...
...
@@ -1221,15 +1126,6 @@ RelationInvalidateCatalogCacheTuple(Relation relation,
Assert
(
PointerIsValid
(
function
));
CACHE1_elog
(
DEBUG
,
"RelationInvalidateCatalogCacheTuple: called"
);
/* ----------------
* switch to the cache memory context
* ----------------
*/
if
(
!
CacheMemoryContext
)
CreateCacheMemoryContext
();
oldcxt
=
MemoryContextSwitchTo
(
CacheMemoryContext
);
/* ----------------
* for each cache
* if the cache contains tuples from the specified relation
...
...
@@ -1244,20 +1140,8 @@ RelationInvalidateCatalogCacheTuple(Relation relation,
if
(
relationId
!=
ccp
->
relationId
)
continue
;
#ifdef NOT_USED
/* OPT inline simplification of CatalogCacheIdInvalidate */
if
(
!
PointerIsValid
(
function
))
function
=
CatalogCacheIdInvalidate
;
#endif
(
*
function
)
(
ccp
->
id
,
CatalogCacheComputeTupleHashIndex
(
ccp
,
relation
,
tuple
),
&
tuple
->
t_self
);
}
/* ----------------
* return to the proper memory context
* ----------------
*/
MemoryContextSwitchTo
(
oldcxt
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录