Subscribe to Posts by Email

Subscriber Count

    701

Disclaimer

All information is offered in good faith and in the hope that it may be of use for educational purpose and for Database community purpose, but is not guaranteed to be correct, up to date or suitable for any particular purpose. db.geeksinsight.com accepts no liability in respect of this information or its use. This site is independent of and does not represent Oracle Corporation in any way. Oracle does not officially sponsor, approve, or endorse this site or its content and if notify any such I am happy to remove. Product and company names mentioned in this website may be the trademarks of their respective owners and published here for informational purpose only. This is my personal blog. The views expressed on these pages are mine and learnt from other blogs and bloggers and to enhance and support the DBA community and this web blog does not represent the thoughts, intentions, plans or strategies of my current employer nor the Oracle and its affiliates or any other companies. And this website does not offer or take profit for providing these content and this is purely non-profit and for educational purpose only. If you see any issues with Content and copy write issues, I am happy to remove if you notify me. Contact Geek DBA Team, via geeksinsights@gmail.com

Pages

Quick Question: When is my table last accessed? Does my index is in use?

The question is tricky,

I have asked accessed not modified/changed. If so modified/changed dba_tab_modifications can give you a clue.

For both of this questions, the below query will help.

Table is in use or not? This question may arise from App team that they have released a new module which may not require certain tables , but before dropping they want to confirm that no query using those tables,

select p.object_owner owners, p.object_name Obj_Name, p.operation Operation, p.options Options, count(1) Idx_Usg_Cnt from dba_hist_sql_plan p,dba_hist_sqlstat s where p.object_owner = '&USERNAME' and p.operation like 'TABLE%' and p.sql_id = s.sql_id and p.object_name='&OBJNAME' group by p.object_owner,p.object_name,p.operation,p.options order by 1,2,3

Similarly Index is in use or not? This question may arise from App team or from DBA team, does certain index has an value or an overhead to the storage, so if any sql execution plans does not use that index it means that index does not need at all.

For a given object i.e index

select p.object_owner owners, p.object_name Obj_Name, p.operation Operation, p.options Options, count(1) Idx_Usg_Cnt from dba_hist_sql_plan p,dba_hist_sqlstat s where p.object_owner = '&USERNAME' and p.operation like '%INDEX' and p.sql_id = s.sql_id and p.object_name='&objname' group by p.object_owner, p.object_name,p.operation,p.options order by 1,2,3;

For a given owner i.e schema level,

So if you found index with count zero, that means that index is not used at all any time in execution plan.

select p.object_owner owners, p.object_name Obj_Name, p.operation Operation, p.options Options, count(1) Idx_Usg_Cnt from dba_hist_sql_plan p,dba_hist_sqlstat s where p.object_owner = '&USERNAME' and p.operation like '%INDEX' and p.sql_id = s.sql_id  group by p.object_owner, p.object_name,p.operation,p.options order by 1,2,3;

For just to find only index that has count zero means never used,  add condition having count(1) <=0

select p.object_owner owners, p.object_name Obj_Name, p.operation Operation, p.options Options, count(1) Idx_Usg_Cnt from dba_hist_sql_plan p,dba_hist_sqlstat s where p.object_owner = '&USERNAME' and p.operation like '%INDEX' and p.sql_id = s.sql_id  group by p.object_owner, p.object_name,p.operation,p.options having Idx_usg_cnt <=0 order by 1,2,3;

 

Another script to use track of object usage. This will show you the date & time as well

select to_char(sn.begin_interval_time,'yy-mm-dd hh24') Begin_Int_Time, p.search_columns Search_Col, count(*) Invocation_Cnt from dba_hist_snapshot sn, dba_hist_sql_plan p, dba_hist_sqlstat st where st.sql_id = p.sql_id and sn.snap_id = st.snap_id and lower(object_name) like /*lower('%&idxname%')*/ lower ('Idx_Name') group by begin_interval_time,search_columns

-Thanks

Geek DBA

3 comments to Quick Question: When is my table last accessed? Does my index is in use?