问题:把表数据放入DATABASE BUFFER中,把表的查询结果放入result_cache,一旦表的行更改会自动同步到这些内存中吗?
答案:
不会
,而是重新访问数据文件进行查询。
ORACLE官方支持的回复
如果表中的数据有行增加或者更新,当再次访问相关的表或执行查询时, Oracle能检测到这种数据的更新,访问数据文件来进行查询。不是定时的把数据文件中的数据同步到KEEP buffer pool 、database buffer cache、result cache 中。
把对象放入内存的四种方法:DBMS_SHARED_POOL.KEEP、buffer_pool keep、cache、result_cache
DBMS_SHARED_POOL.KEEP和result_cache都是放入shared_pool中
buffer_pool keep、cache都是放入database buffer中
BUFFER_POOL用来指定存贮的缓冲池,而CACHE/NOCACHE指定存储的方式。当BUFFER_POOL和CACHE同时使用时,KEEP比NOCACHE有优先权。
DBMS_SHARED_POOL.KEEP
('0034CDFF,20348871','C')
DBMS_SHARED_POOL.KEEP 用于把PL/SQL对象,触发器,以及SQL游标等保持在shared pool中。这与表和查询结果是不同的对象。
查询结果见视图v$db_object_cache
select * from v$db_object_cache where kept='YES' and name like 'XX'
Alter table tablename storage (
buffer_pool keep
);
查询结果见视图DBA_TABLES
select owner,table_name,buffer_pool from dba_tables where BUFFER_POOL='KEEP'
取消表放入缓存
Alter table tablename storage (buffer_pool default);
Alter table tablename
cache
查询结果见视图DBA_TABLES
select owner,table_name,cache from dba_tables where cache=' Y'
取消表放入缓存
Alter table tablename nocache
Alter table tablename
result_cache
(mode force);
查询结果见视图V$RESULT_CACHE_OBJECTS
result_cache是shared pool中的一块区域,用于保持查询的结果集
已经试验过,
表的行数有更改时,V$RESULT_CACHE_OBJECTS.STATUS变成了Invalid
,也就是说Result Cache使用的一个前提:目标数据表不怎么变化。
DBMS_SHARED_POOL.KEEP
This procedure keeps an object in the shared pool. Once an object has been kept in the shared pool, it is not subject to aging out of the pool. This may be useful for frequently used large objects.
此过程将对象保留在共享池中。 一旦对象保留在共享池中,它就不会从池中老化。 这对于经常使用的大型对象可能很有用。
BUFFER_POOL
The BUFFER_POOL clause lets you specify a default buffer pool or cache for a schema object. All blocks for the object are stored in the specified cache.
When the buffer pool of an object is changed using the ALTER statement, all buffers currently containing blocks of the altered segment remain in the buffer pool they were in before the ALTER statement.
Newly loaded blocks and any blocks that have aged out and are reloaded go into the new buffer pool
.
The NOCACHE clause has no effect on a table in the KEEP cache
.
BUFFER_POOL子句允许您为架构对象指定默认缓冲池或缓存。 对象的所有块都存储在指定的缓存中。
当使用ALTER语句更改对象的缓冲池时,当前包含已更改段的块的所有缓冲区都保留在ALTER语句之前的缓冲池中。
新加载的块和已经老化并重新加载的任何块都将进入新的缓冲池
。
NOCACHE子句对KEEP缓存中的表没有影响
。
CACHE
For data that is accessed frequently, this clause indicates that the blocks retrieved for this table are placed at the most recently used end of the least recently used (LRU) list in the buffer cache when a full table scan is performed.
This attribute is useful for small lookup tables
.
对于经常访问的数据,此子句指示在执行全表扫描时,为此表检索的块放置在缓冲区高速缓存中最近最少使用(LRU)列表的最近使用的末尾。
此属性对小型查找表很有用
。
RESULT_CACHE
Use this clause to determine whether the results of statements or query blocks that name this table are considered for storage in the result cache.
When users execute queries and functions repeatedly, the database retrieves rows from the cache, decreasing response time.
Cached results become invalid when data in dependent database objects is modified.
使用此子句可确定是否将用于命名此表的语句或查询块的结果视为存储在结果缓存中。
当用户重复执行查询和函数时,数据库将从缓存中检索行,从而缩短响应时间。
当修改依赖数据库对象中的数据时,
缓存结果将变为无效。