您好,登錄后才能下訂單哦!
小編給大家分享一下Oracle中如何找出有哪些索引從來沒有被使用過,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
數據庫經過N手后,索引亂建,下面的SQL就找出一點時間范圍內哪些索引從來沒被使用過,親測好用,注意一點,生成的SQL你要是執行了,就會從腳本中消失了,
SELECT X.OWNER, X.TABLE_NAME, X.INDEX_NAME, C.COLUMN_POSITION, C.COLUMN_NAME, S.BYTES / 1024 / 1024 M, q'[select count(*),count(distinct ]' || C.COLUMN_NAME || q'[) from ]' || X.OWNER || '.' || X.TABLE_NAME || q'[;]' AS QUERY_Q FROM (SELECT A.OWNER, A.TABLE_NAME, A.INDEX_NAME FROM DBA_INDEXES A WHERE A.OWNER IN (SELECT USERNAME FROM DBA_USERS WHERE CREATED > DATE '2018-10-30') AND (A.OWNER, A.INDEX_NAME) NOT IN (SELECT /*+unnest*/ B.OBJECT_OWNER, B.OBJECT_NAME FROM GV$SQL A, GV$SQL_PLAN B WHERE A.SQL_ID = B.SQL_ID AND A.CHILD_NUMBER = B.CHILD_NUMBER AND B.OBJECT_OWNER IN (SELECT USERNAME FROM DBA_USERS WHERE CREATED > DATE '2018-10-30') AND B.OBJECT_TYPE LIKE '%INDEX%' AND B.TIMESTAMP > DATE '2018-10-10') AND A.TABLE_NAME NOT LIKE 'SYS%' AND A.UNIQUENESS <> 'UNIQUE') X INNER JOIN DBA_IND_COLUMNS C ON C.INDEX_OWNER = X.OWNER AND C.INDEX_NAME = X.INDEX_NAME AND C.TABLE_NAME = X.TABLE_NAME INNER JOIN DBA_SEGMENTS S ON S.SEGMENT_NAME = C.TABLE_NAME AND S.OWNER = C.INDEX_OWNER AND S.BYTES / 1024 / 1024 > 10 ORDER BY 1, 2, 3, 4;
以上是“Oracle中如何找出有哪些索引從來沒有被使用過”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。