all_tab_modifications

当我们需要统计一个表被操作的次数时,有个很重要的视图:all_tab_modifications,它会提供一个表的被操作(insert,update,delete等)的统计信息,看下官方说明:

ALL_TAB_MODIFICATIONS describes tables accessible to the current user that have been modified since the last time statistics were gathered on the tables.

Note:

These views are populated only for tables with the MONITORING attribute. They are intended for statistics collection over a long period of time. For performance reasons, the Oracle Database does not populate these views immediately when the actual modifications occur. Run the FLUSH_DATABASE_MONITORING_INFO procedure in the DBMS_STATS PL/SQL package to populate these views with the latest information. The ANALYZE_ANY system privilege is required to run this procedure.

通过官方解释,我们可以看到,要使用这个功能,前提是表的MONITORING属性要开启(DBA_TABLES)中可以看到表的这个属性(为YES才行)。

其次这个视图不会实时刷新,除非你调用过程:dbms_stats.FLUSH_DATABASE_MONITORING_INFO();

看下实验过程:

1.首先看表A的MONITORING属性

 SELECT t.MONITORING FROM dba_tables t WHERE t.TABLE_NAME='A';

MON
---
YES

2.插入记录

INSERT  INTO a SELECT * FROM a;

3.查询统计信息

SELECT * FROM  all_tab_modifications WHERE table_owner='ORACLE';

你会发现没有任何提供的显示信息,执行过程

BEGIN
  dbms_stats.FLUSH_DATABASE_MONITORING_INFO();
END;

再进行表A操作信息的查询

SELECT * FROM  all_tab_modifications WHERE table_owner='ORACLE';

这个时候就能看到刚刚进行的操作信息了


所以如果你想知道一个过程中对表进行了多少次操作,你应该在执行前flush一次,过程执行完毕后再flush一次,用两次统计的差值来进行分析


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值