【TUNE_ORACLE】檢查統計資訊是否過期SQL參考

Attack_on_Jager發表於2021-08-04

實驗環境

搭建平臺:VMware Workstation

OS:RHEL 6.10

Grid&DB:Oracle 11.2.0.4


SQL參考

--1. 首先執行explain plan for,在plan_table中生成SQL的執行計劃

explain plan for select ....


--2. 然後執行以下指令碼檢查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%'));


--3. 最後檢查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%'));


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69992972/viewspace-2785127/,如需轉載,請註明出處,否則將追究法律責任。

相關文章