十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
小编给大家分享一下Oracle中如何找出有哪些索引从来没有被使用过,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
创新互联建站成立与2013年,先为禹王台等服务建站,禹王台等地企业,进行企业商务咨询服务。为禹王台企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
数据库经过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中如何找出有哪些索引从来没有被使用过”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!