索引语法

索引分类:
[list]
[*]唯一索引,作用是[color=red]数据约束,保证数据唯一[/color],还有就是数据索引,提高查询效率
[*]一般索引,只有数据索引的作用。
[/list]
唯一索引:
create unique index idx_employee_empname on employee(empname);

一般索引:
create index idx_employee_address on employee(address);
create unique index idx_employee_field1_field2 on employee(field1,field2);

函数索引:
create index idx_product_nvl_price on product(nvl(price,0.0));

删除索引:
drop index idx_employee_empname;

指定索引表空间
create index idx_employee_address on employee(address) tablespace indexs;

查看索引
select * from user_indexes where table_name = 'SHOP_PD'

参考:
[url]http://www.java2s.com/Tutorial/Oracle/0180__Index/Createindexwithtablespace.htm[/url]
[url]http://hi.baidu.com/luodaijun/blog/item/2ea274f065c856aea50f5219.html[/url]

以下情况下索引会失效
[list]
[*]查询条件中字段使用顺序和组合索引定义中字段的顺序不一致时,索引无效[color=red]oracle 10这种情况下索引已经起作用,低版本的不起作用[/color]
[*]使用!=,<>操作符会限制索引,换成 > or < 不会[color=red]oracle 10这种情况下索引已经起作用,低版本的不起作用[/color]
[*]对索引列使用函数会忽略索引[color=red]必要的情况下,可以建立函数索引[/color]
[*]试着对被SUM,MAX,MIN的列增加索引
[/list]

有时候索引不起作用是因为oralce在使用基于成本的优化器(CBO),走索引的代价反而更加高,使得sql走全表扫描,可以如下使用强制索引语法,然后查看执行计划中的消耗
select /*+ index(t,IDX_AR_JDXX_SELL)*/t.province, t.city, t.country
from ar_sell t
group by t.type_code,t.province, t.city, t.country

参考:
[url]http://wenku.baidu.com/view/e8470b1aff00bed5b9f31d99.html[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值