Oracle中select语句使用索引情况测试

WBOY
풀어 주다: 2016-06-07 17:06:08
원래의
986명이 탐색했습니다.

--看了不少Oracle中sql优化的文章,也介绍了很多不使用索引的情况,今天有空就测试了一下部分情况。 --测试数据 create table EM

--看了不少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中则不使用索引。

linux

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!