--看了不少Oracle中sql优化的文章,也介绍了很多不使用索引的情况,今天有空就测试了一下部分情况。
--测试数据
create table EMP
(
EMPNO VARCHAR2(10) not null primary key,
ENAME VARCHAR2(10),
JOB VARCHAR2(10),
MGR VARCHAR2(10),
SAL NUMBER(10),
DEPTNO NUMBER(10)
) create index I_DEPTNO on EMP (DEPTNO);
create index I_JOB on EMP (JOB);
create index I_MGR on EMP (MGR);
create index I_SAL on EMP (SAL); insert into emp values ("01","jacky","clerk","tom","1000","1");
insert into emp values ("02","tom","clerk","","2000","1");
insert into emp values ("03","jenny","sales","pretty","600","2");
insert into emp values ("04","pretty","sales","","800","2");
insert into emp values ("05","buddy","jishu","canndy","1000","3");
insert into emp values ("06","canndy","jishu","","1500","3");
insert into emp values ("07","biddy","clerk","","2000","1");
insert into emp values ("08","biddy","clerk","","2000","3");
commit;
--测试及结果:
select * from emp where deptno = 1;
--使用索引
select * from emp where deptno = "1";
--使用索引(类型转换不影响索引使用) select * from emp where deptno*2 = 2;
--全表扫描(索引列使用函数时不使用索引)
select * from emp where deptno = 2/2;
--使用索引 select * from emp where ename = "tom" and deptno = 1;
--使用索引
select * from emp where ename = "tom" or deptno = 1;
--全表扫描 (当or条件列都存在索引时会使用索引) select * from emp where sal != "0";
--全表扫描(!=,null,not null都不使用索引) select * from emp where mgr = "tom";
--使用索引(虽然mgr列存在null值还是使用了索引) select * from emp where deptno in ("1","2","3");
--使用索引(in使用索引) select * from emp where job like "c%";
--使用索引(%在第一个字符时不使用索引) select * from emp where deptno between 1 and 2;
--使用索引 --补充一个不使用索引的情况:多列创建索引时,索引第一列不在where中则不使用索引。 Java调用Oracle存储过程教程MySQL 查询后插入或更新导致表损坏解决方法相关资讯 Oracle数据库 Oracle入门教程 oracle数据库教程
- Oracle数据库全球化 (03月01日)
- Oracle数据库日期过滤方法性能比较 (02/02/2015 13:20:26)
- Oracle数据库安装中端口被占用问题 (10/29/2014 07:42:24)
| - 在CentOS 6.6上搭建C++运行环境并 (10/10/2015 19:44:40)
- Oracle数据库无法使用localhost和 (11/14/2014 16:39:10)
- 使用SQLT来构建Oracle测试用例 (08/28/2014 06:17:41)
|
本文评论 查看全部评论 (0)