oracle索引的5种使用模式
2010-10-08 11:25
555 查看
索引的使用对数据库的性能有巨大的影响。
共有五类不同的使用模式。
1。INDEX UNIQUE SCAN 效率最高,主键或唯一索引
2。INDEX FULL SCAN 有顺序的输出,不能并行读索引
3。INDEX FAST FULL SCAN 读的最块,可以并行访问索引,但输出不按顺序
4。INDEX RANGE SCAN 给定的区间查询
5。INDEX SKIP SCAN 联合索引,不同值越少的列,越要放在前面
--实验后的总论。
能用唯一索引,一定用唯一索引
能加非空,就加非空约束
一定要统计表的信息,索引的信息,柱状图的信息。
联合索引的顺序不同,影响索引的选择,尽量将值少的放在前面
只有做到以上四点,数据库才会正确的选择执行计划。
conn system/manager
grant select any dictionary to scott;
conn scott/tiger
drop table t1 purge;
create table t1 as select * from dba_objects;
analyze table t1 compute statistics;
create index it1 on t1(object_type);
set autot traceonly
select distinct object_type from t1;
将是全表扫描,为什么不使用索引呢?因为索引中不能含有null值,
如果使用索引就可能产生不正确的结果。
--增加非空约束
alter table t1 modify (object_type not null);
select distinct object_type from t1 ;
使用INDEX FAST FULL SCAN方式查找数据
--
select object_type from t1;
使用INDEX FAST FULL SCAN,因为不需要排序
select object_type from t1 order by 1;
使用INDEX FULL SCAN,因为要按照顺序输出
select object_type from t1 where object_type='TABLE';
使用INDEX RANGE SCAN
--使用非唯一索引
create index i2t1 on t1(object_id);
select * from t1 where object_id=3762;
使用INDEX RANGE SCAN,因为数据库不知道是否唯一
--使用唯一索引
drop index i2t1;
create unique index i2t1 on t1(object_id);
使用INDEX UNIQUE SCAN,因为数据库知道是唯一的
--跳跃的扫描索引
create index i3t1 on t1(object_type,object_name);
select * from t1 where object_name='EMP';
select object_name from t1 where object_name='EMP';
使用INDEX SKIP SCAN,因为数据库知道可以跳过object_type,虽然object_name在第二个列。
--联合索引的顺序不同,影响索引的选择,尽量将值少的放在前面
drop index i3t1;
drop index it1;
create index i3t1 on t1(object_name,object_type);
select * from t1 where object_type='TABLE';
计划为全表扫描。
共有五类不同的使用模式。
1。INDEX UNIQUE SCAN 效率最高,主键或唯一索引
2。INDEX FULL SCAN 有顺序的输出,不能并行读索引
3。INDEX FAST FULL SCAN 读的最块,可以并行访问索引,但输出不按顺序
4。INDEX RANGE SCAN 给定的区间查询
5。INDEX SKIP SCAN 联合索引,不同值越少的列,越要放在前面
--实验后的总论。
能用唯一索引,一定用唯一索引
能加非空,就加非空约束
一定要统计表的信息,索引的信息,柱状图的信息。
联合索引的顺序不同,影响索引的选择,尽量将值少的放在前面
只有做到以上四点,数据库才会正确的选择执行计划。
conn system/manager
grant select any dictionary to scott;
conn scott/tiger
drop table t1 purge;
create table t1 as select * from dba_objects;
analyze table t1 compute statistics;
create index it1 on t1(object_type);
set autot traceonly
select distinct object_type from t1;
将是全表扫描,为什么不使用索引呢?因为索引中不能含有null值,
如果使用索引就可能产生不正确的结果。
--增加非空约束
alter table t1 modify (object_type not null);
select distinct object_type from t1 ;
使用INDEX FAST FULL SCAN方式查找数据
--
select object_type from t1;
使用INDEX FAST FULL SCAN,因为不需要排序
select object_type from t1 order by 1;
使用INDEX FULL SCAN,因为要按照顺序输出
select object_type from t1 where object_type='TABLE';
使用INDEX RANGE SCAN
--使用非唯一索引
create index i2t1 on t1(object_id);
select * from t1 where object_id=3762;
使用INDEX RANGE SCAN,因为数据库不知道是否唯一
--使用唯一索引
drop index i2t1;
create unique index i2t1 on t1(object_id);
使用INDEX UNIQUE SCAN,因为数据库知道是唯一的
--跳跃的扫描索引
create index i3t1 on t1(object_type,object_name);
select * from t1 where object_name='EMP';
select object_name from t1 where object_name='EMP';
使用INDEX SKIP SCAN,因为数据库知道可以跳过object_type,虽然object_name在第二个列。
--联合索引的顺序不同,影响索引的选择,尽量将值少的放在前面
drop index i3t1;
drop index it1;
create index i3t1 on t1(object_name,object_type);
select * from t1 where object_type='TABLE';
计划为全表扫描。
相关文章推荐
- oracle索引的5种使用模式
- RabbitMQ入门及常用的5种模式的简单使用(二)
- 5种iOS编程中使用的设计模式
- Launching Applications with spark-submit【使用脚本提交作业到集群5种部署模式--】
- oracle index的5种使用模式
- RabbitMQ入门及常用的5种模式的简单使用(一)
- JavaScript面向对象 组合使用构造函数模式和原型模式
- 设计模式- 使用抽象工厂实现多数据库切换实现过程
- 通过fsharp 使用Enterprise Library Unity 3 - 三种拦截模式的探索
- 【JAVA】设计模式之命令模式(Command模式)的使用分析
- 模式修正符 -- 解说正则表达式模式中使用的修正符
- 学习实践:使用模式,原则实现一个C++自动化测试程序
- Working with ADO.NET Schema APIs 使用ADO.NET 模式API
- 使用命令行模式启动VMWare虚拟机
- Tomcat在debug模式下启动,使用eclipse监听
- 变种Builder模式的自动化生成工具的下载、生效和使用
- 委托、事件、Observer观察者模式的使用解析一
- Ubuntu的vi不能正常进入插入模式,按方向键出现ABCD,以及退格键不能使用解决方案
- 如何使用设计模式来构造系统--(5)
- java中单例模式(饿汉式、懒汉式)的使用