oracle中冗余,各位有没有检查冗余索引的脚本

查看数据库中有无多余的索引,即一个索引的字段为另一个索引的前几个字段。如index1的定义为test(filed1,filed2),index2的定义为test(filed1,filed2,filed3),则认为index1是多余的。

查看数据库中有无多余的索引,即一个索引的字段为另一个索引的前几个字段。如index1的定义为test(filed1,filed2),index2的定义为test(filed1,filed2,filed3),则认为index1是多余的。

-------------------------------------------------------------------------------

--

-- Script: redundant_indexes.sql

-- Purpose: to find any redundant indexes

-- For:  8.0 and 8.1

--

-- Copyright: (c) Ixora Pty Ltd

-- Author: Steve Adams

--

-------------------------------------------------------------------------------

column redundant_index format a39

column sufficient_index format a39

select

o1.name||'.'||n1.name  redundant_index,

o2.name||'.'||n2.name  sufficient_index

from

sys.icol$  ic1,

sys.icol$  ic2,

sys.ind$  i1,

sys.obj$  n1,

sys.obj$  n2,

sys.user$  o1,

sys.user$  o2

where

ic1.pos# = 1 and

ic2.bo# = ic1.bo# and

ic2.obj# != ic1.obj# and

ic2.pos# = 1 and

ic2.intcol# = ic1.intcol# and

i1.obj# = ic1.obj# and

bitand(i1.property, 1) = 0 and

( select

max(pos#) * (max(pos#) + 1) / 2

from

sys.icol$

where

obj# = ic1.obj#

) =

( select

sum(xc1.pos#)

from

sys.icol$ xc1,

sys.icol$ xc2

where

xc1.obj# = ic1.obj# and

xc2.obj# = ic2.obj# and

xc1.pos# = xc2.pos# and

xc1.intcol# = xc2.intcol#

) and

n1.obj# = ic1.obj# and

n2.obj# = ic2.obj# and

o1.user# = n1.owner# and

o2.user# = n2.owner#

/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值