Oracle性能优化之索引

查询DBA_INDEXES视图可得到表中所有索引的列表,注意只能通过USER_INDEXES的方法来检索模式(schema)的索引。访问USER_IND_COLUMNS视图可得到一个给定表中被索引的特定列。
查询某一用户拥有的所有索引:
Login as SYSDBA -> [b]select owner,index_name,index_type,table_name from [color=red]dba_indexes[/color] where owner = 'username' order by table_name;[/b]
查询模式(schema)的索引:
Nomal Login -> [b]select * from user_indexes;[/b]
查询当前登录用户拥有的索引及其对应的表、列:
Nomal Login -> [b]select * from user_ind_columns;[/b]

Oracle Index 索引介绍
作者:mjgforever
[url]http://www.cnblogs.com/mjgforever/archive/2008/01/15/1040427.html[/url]

Oracle Index 的三个问题:
[url]http://hi.baidu.com/mifan21/blog/item/305bf650e626ab541038c295.html[/url]

使用ORACLE索引的一些小技巧:
[url]http://hi.baidu.com/west_life/blog/item/c0c0a80f76c9e2e4ab6457ce.html[/url]

索引的分类、建立与删除:
[url]http://hi.baidu.com/luodaijun/blog/item/2ea274f065c856aea50f5219.html[/url]
1.索引分类
[b]插一句:逻辑上分为单列索引/联合索引,唯一索引/不唯一索引,寄予函数的索引,域内索引;物理上分为分布式索引/集中式索引,B-tree索引,bitmap索引。[/b]
a) 唯一索引, 作用是数据约束,保证数据唯一,还有就是数据索引,提高查询效率
b)一般索引,只有数据索引的作用,
2.唯一索引的建立
create unique index 索引名 on 表名(字段名)
ok,假设有一个Emploeyy表,里面有一个empName字段,我们来为empName添加唯一索引
create unique index idx_empname on employee(empname);
3.一般索引
create index 索引名 on 表名(字段名)
ok,现在我们为employee的address字段,添加一般索引
create index idx_address on employee(address);
我们还可以为两多个字段建立索引
create unique index idx_test on employee(field1,field2);
这样,为field1,field2添加了唯一索引,field1和field2的组合是唯一的了
还可以指定索引排序
create index idx_test employee(field1 ,field2 desc);;
4.函数索引
如果在我们的查询条件使用了函数,那么索引就不可用了。
可以用建立函数索引的方式,来解决这个问题
例如:
select * from product where nvl(price,0.0)>1000.0 ;
这里,nvl(price,0.0)使用了函数,索引不能利用price字段上做的索引了
ok,我们来创建函数索引
create index index_price on product(nvl(price,0.0));
5.索引的删除
drop index 索引名
drop index idx_empname;
6.其它的
唯一索引能极大的提高查询速度,而且还有唯一约束的作用
一般索引,只能提高30%左右的速度
经常插入,修改,应在查询允许的情况下,尽量减少索引,因为添加索引,插入,修改等操作,需要更多的时间
可以在order by的字段,where的条件字段,join的关联字段添加索引
比如:
select * from table1 t1
left join table2 t2 on t1.字段A=t2.字段B
where t1.字段C = '值'
order by t1.字段D
这里,A,B,C,D字段,都应该添加索引
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值