zoukankan      html  css  js  c++  java
  • 多个表关联或者有视图套视图,快速检查SQL语句中所有的表统计信息是否过期

    多个表关联或者有视图套视图,快速检查SQL语句中所有的表统计信息是否过期
    现有如下SQL:
    select * from emp e,dept d where e.deptno=d.deptno;
     
    先用explain plan for命令,在plan_table中生成SQL的执行计划:
     
    SQL> explain plan for select * from emp e,dept d where e.deptno=d.deptno;
     
    Explained.
     
    然后使用下面脚本检查SQL语句中所有的表的统计信息是否过期:
     
    SQL> select owner, table_name, object_type, stale_stats, last_analyzed
    from dba_tab_statistics
    where (owner, table_name) in
    (select object_owner, object_name
    from plan_table
    where object_type like '%TABLE%'
    union
    select table_owner, table_name
    from dba_indexes
    where (owner, index_name) in
    (select object_owner, object_name
    from plan_table
    where object_type like '%INDEX%'));
     
    OWNER TABLE_NAME OBJECT_TYP STALE_STATS LAST_ANALYZED
    ---------- ---------- ---------- --------------- ------------------
    SCOTT DEPT TABLE NO 05-DEC-16
    SCOTT EMP TABLE YES 22-OCT-16
     
     
    最后可以使用下面脚本检查SQL语句中表统计信息的过期原因:
     
    select *
      from all_tab_modifications
     where (table_owner, table_name) in
           (select object_owner, object_name
              from plan_table
             where object_type like '%TABLE%'
            union
            select table_owner, table_name
              from dba_indexes
             where (owner, index_name) in
                   (select object_owner, object_name
                      from plan_table
                     where object_type like '%INDEX%'));
     
     
     
  • 相关阅读:
    将字符串数组转换成整形数组
    层的三级联动
    sql
    工作中的感悟
    asp.net如何抓取其他网站的内容
    看不到的SQl
    对数据库中时间为空的处理和数据转换成百分数
    不带查询条件的分页
    svn中出现红色感叹号
    视图的创建(根据已有的表)
  • 原文地址:https://www.cnblogs.com/liang545621/p/12611893.html
Copyright © 2011-2022 走看看