博客园 首页 联系 订阅 管理

(1)Oracle提供了一个内部事件,用以强制刷新Buffer Cache,其语法为:

 alter system set events 'immediate trace name flush_cache';

1.清空共享池和缓冲区缓存(被硬解析,包含查询所需数据的块,需要从磁盘上物理读取)
SQL> alter system set events 'immediate trace name flush_cache';

System altered.

SQL> alter system flush shared_pool;

System altered.

SQL> set autotrace traceonly statistics
SQL> select * from dept;


Statistics
----------------------------------------------------------
        355  recursive calls
          0  db block gets
         68  consistent gets
         20  physical reads
          0  redo size
        666  bytes sent via SQL*Net to client
        415  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          6  sorts (memory)
          0  sorts (disk)
          4  rows processed
2.仅清空缓冲区缓存
SQL> alter system set events 'immediate trace name flush_cache';

System altered.

SQL> set autotrace traceonly statistics
SQL> select * from dept;


Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
          8  consistent gets
          6  physical reads
          0  redo size
        666  bytes sent via SQL*Net to client
        415  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          4  rows processed
3.都不清空
SQL> select * from dept;


Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
          8  consistent gets
          0  physical reads
          0  redo size
        666  bytes sent via SQL*Net to client
        415  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          4  rows processed

总结:当执行一个查询仅需要进行软解析并且从缓冲区缓存中读取数据块时,执行任务所耗占的资源是最少的