資料庫物件比如表放入記憶體,行發生改變不會自動同步到記憶體的總結

lusklusklusk發表於2018-11-07

問題:把表資料放入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.

使用此子句可確定是否將用於命名此表的語句或查詢塊的結果視為儲存在結果快取中。

當使用者重複執行查詢和函式時,資料庫將從快取中檢索行,從而縮短響應時間。 當修改依賴資料庫物件中的資料時, 快取結果將變為無效。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30126024/viewspace-2219124/,如需轉載,請註明出處,否則將追究法律責任。

相關文章