ITPub博客

首页 > 应用开发 > IT综合 > 请慎重分析对象!

请慎重分析对象!

原创 IT综合 作者:warehouse 时间:2008-04-16 10:06:24 0 删除 编辑
对象被分析之后,所有和该对象相关的被parse过的sql都会失效,下次需要执行相同的sql时需要再次parse,因此当系统执行过搜集statistics的操作后面临的可能是在短时间内产生很多hard parse。 其实非常容易理解,因为有了新的statistics,oracle在下次执行相同的sql时会使用新的statistics产生新的执行计划。[@more@]

When you generate statistics for a table, column, or index, if the data dictionary already contains statistics for the object, then Oracle updates the existing statistics. Oracle also invalidates any currently parsed SQL statements that access the object.

session1:

SQL> alter system flush shared_pool;

系统已更改。

SQL> alter system flush buffer_cache;

系统已更改。

SQL> select * from tt;

ID NAME AGE
---------- ----------------------------------- ----------
3 b 0
4 b 0
6 b 0
0 a 0

SQL> select namespace,reloads,invalidations from v$librarycache;

NAMESPACE RELOADS INVALIDATIONS
--------------- ---------- -------------
SQL AREA 240 1326
TABLE/PROCEDURE 958 0
BODY 6 0
TRIGGER 0 0
INDEX 0 0
CLUSTER 0 0
OBJECT 0 0
PIPE 0 0
JAVA SOURCE 0 0
JAVA RESOURCE 0 0
JAVA DATA 0 0

已选择11行。

SQL> select a.*,b.name
2 from v$sesstat a , v$statname b
3 where a.statistic#=b.statistic#
4 and b.name like '%parse%'
5 and a.sid=(select sid from v$mystat where rownum=1);

SID STATISTIC# VALUE NAME
---------- ---------- ---------- -----------------------------------
137 430 146 parse time cpu
137 431 479 parse time elapsed
137 432 1623 parse count (total)
137 433 557 parse count (hard)
137 434 4 parse count (failures)

为了准确观察parse的次数,减少在同一个session中analyze table tt compute statistics;所引起的干扰,另开一个session执行analyze table tt compute statistics:

session2:

SQL> analyze table tt compute statistics;

表已分析。

再回到session1:

SQL> select * from tt;

ID NAME AGE
---------- ----------------------------------- ----------
3 b 0
4 b 0
6 b 0
0 a 0

SQL> select namespace,reloads,invalidations from v$librarycache;

NAMESPACE RELOADS INVALIDATIONS
--------------- ---------- -------------
SQL AREA 331 1328
TABLE/PROCEDURE 986 0
BODY 8 0
TRIGGER 0 0
INDEX 0 0
CLUSTER 0 0
OBJECT 0 0
PIPE 0 0
JAVA SOURCE 0 0
JAVA RESOURCE 0 0
JAVA DATA 0 0

已选择11行。

SQL> select a.*,b.name
2 from v$sesstat a , v$statname b
3 where a.statistic#=b.statistic#
4 and b.name like '%parse%'
5 and a.sid=(select sid from v$mystat where rownum=1);

SID STATISTIC# VALUE NAME
---------- ---------- ---------- -----------------------------------
137 430 146 parse time cpu
137 431 479 parse time elapsed
137 432 1629 parse count (total)
137 433 558 parse count (hard)
137 434 4 parse count (failures)

SQL>

通过对比发现分析tt前后的INVALIDATIONS和parse count

都增加了,尽管执行了相同的sql:select * from tt;

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/19602/viewspace-1002596/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: statistics!
请登录后发表评论 登录
全部评论

注册时间:2007-12-07

  • 博文量
    717
  • 访问量
    5366329