logo 广告
Loading...
 导航 所在位置:论坛首页 -> ┈┋电脑网络┋┈ -> 数据库技术 -> 脚本示例:查看数据库中有无多余的索引SQL
回复
标题:脚本示例:查看数据库中有无多余的索引SQL收藏 编辑 删除 楼主 | 上一篇 下一篇
只看该用户
头像
等级:社区游侠
权限:普通用户
积分:42
金钱:206
声望:76
经验:63
发帖数:106
注册:2008年6月24日
资料 短消息2008-7-4 11:06:01
查看数据库中有无多余的索引,即一个索引的字段为另一个索引的前几个字段。如index1的定义为test(filed1,filed2),index2的定义为test(filed1,filed2,filed3),则认为index1是多余的。(摘自Ixora)

column redundant_index format a39

column sufficient_index format a39

select /*+ ordered */

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

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

from

(

select

obj#,

bo#,

count(*) cols,

max(decode(pos#, 1, intcol#)) leadcol#

from

sys.icol$

group by

obj#,

bo#

) ic1,

sys.icol$ ic2,

sys.ind$ i1,

sys.obj$ n1,

sys.obj$ n2,

sys.user$ o1,

sys.user$ o2

where

ic2.obj# != ic1.obj# and

ic2.bo# = ic1.bo# and

ic2.pos# = 1 and

ic2.intcol# = ic1.leadcol# and

i1.obj# = ic1.obj# and

bitand(i1.property, 1) = 0 and

ic1.cols * (ic1.cols + 1) / 2 =

( 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#

/

签名

2008-7-4 11:06:01 顶部
第1页 共页 共0个回复     <<    >>    
 快速回复
  • 支持UBB,HTML标签

  • 高级回复

  • 操作选项:评分 加精 解精 奖惩 设专题 设公告 解公告 固顶 总固顶 解固顶 结帖 解结帖 锁帖 解锁 移帖 删帖
      首页 | 购买指南 | 虚拟主机 | 特色介绍 | 下载中心 | 支付方式
    Copyright 2004-2008 BBSGood.com Powered By: BBSGood.Speed Version 5.0
      咨询电话:0575-85513832、0575-85513825(传真)、7*24小时咨询服务:13606552007 不良信息举报中心 浙ICP备05029817号
      业务QQ:38958768、客服QQ1:415896239、客服QQ2:343896043、MSN:jccsxx@hotmail.com