暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

oracle清除SQL缓存实例

原创 章芋文 2012-03-27
1231
[size=3]打开sql跟踪的功能:
SQL> set autotrace traceonly;

执行下面的SQL看计划:
SQL> select * from awen.ob_bak where owner='AWEN';

已选择2304行。


执行计划
----------------------------------------------------------
Plan hash value: 709901947

----------------------------------------------------------------------------------------

| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |

----------------------------------------------------------------------------------------

| 0 | SELECT STATEMENT | | 774K| 68M| 27184 (2)| 00:00:33 |

| 1 | TABLE ACCESS BY INDEX ROWID| OB_BAK | 774K| 68M| 27184 (2)| 00:00:33 |

|* 2 | INDEX RANGE SCAN | OB_INDEX | 774K| | 1860 (4)| 00:00:03 |

----------------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------

2 - access("OWNER"='AWEN')


统计信息
----------------------------------------------------------
1 recursive calls
0 db block gets
1466 consistent gets
[color=Red] 1258 physical reads[/color]
0 redo size
220074 bytes sent via SQL*Net to client
2068 bytes received via SQL*Net from client
155 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2304 rows processed

有1258 次physical reads,再次运行同样的SQL,看执行计划:
SQL> select * from awen.ob_bak where owner='AWEN';

已选择2304行。


执行计划
----------------------------------------------------------
Plan hash value: 709901947

----------------------------------------------------------------------------------------

| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |

----------------------------------------------------------------------------------------

| 0 | SELECT STATEMENT | | 774K| 68M| 27184 (2)| 00:00:33 |

| 1 | TABLE ACCESS BY INDEX ROWID| OB_BAK | 774K| 68M| 27184 (2)| 00:00:33 |

|* 2 | INDEX RANGE SCAN | OB_INDEX | 774K| | 1860 (4)| 00:00:03 |

----------------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------

2 - access("OWNER"='AWEN')


统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
1466 consistent gets
[color=Red] 0 physical reads[/color]
0 redo size
220074 bytes sent via SQL*Net to client
2068 bytes received via SQL*Net from client
155 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2304 rows processed

0个 physical reads,说明现在用的是缓存里面保留的数据,

[color=Red]清除缓存:
SQL> alter system flush buffer_cache;[/color]系统已更改。

再次执行SQL,看执行计划:
SQL> select * from awen.ob_bak where owner='AWEN';

已选择2304行。


执行计划
----------------------------------------------------------
Plan hash value: 709901947

----------------------------------------------------------------------------------------

| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |

----------------------------------------------------------------------------------------

| 0 | SELECT STATEMENT | | 774K| 68M| 27184 (2)| 00:00:33 |

| 1 | TABLE ACCESS BY INDEX ROWID| OB_BAK | 774K| 68M| 27184 (2)| 00:00:33 |

|* 2 | INDEX RANGE SCAN | OB_INDEX | 774K| | 1860 (4)| 00:00:03 |

----------------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------

2 - access("OWNER"='AWEN')


统计信息
----------------------------------------------------------
0 recursive calls
0 db block gets
1466 consistent gets
1587 physical reads
0 redo size
220074 bytes sent via SQL*Net to client
2068 bytes received via SQL*Net from client
155 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2304 rows processed

又会有 physical reads 出现。[/size]
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论