Oracle中LIKE语句优化

WBOY
풀어 주다: 2016-06-07 16:59:59
원래의
1171명이 탐색했습니다.

1。尽量不要使用 like

1。尽量不要使用 like '%%'

2。对于 like '%' (不以 % 开头),Oracle可以应用 colunm上的index

3。对于 like '%…' 的 (不以 % 结尾),可以利用reverse + function index 的形式,变化成 like '%'

建测试表和Index,注意,,重点在于带reverse的function index。同时,一定要使用CBO才行

create table test_like as select object_id,object_name from dba_objects;

-------建立测试表

create index test_like__name on test_like(object_name);

------建立索引

create index test_like__name_reverse on test_like(reverse(object_name));

------建立反向索引

analyze table test_like compute statistics for table for all indexes;

------对表进行分析

都过SQLPLUS连接到数据,一定是SQLPLUS,因为下面有写命令在PLSQL的命令行中不被支持;

set autotrace trace exp

-----设定SQL跟踪

set linesize 2000

-------设定输出宽度

select * from test_like where object_name like 'AS%';

使用了索引

select * from test_like where object_name like '%S';

未使用索引

select * from test_like where reverse(object_name)like reverse('%AS');

使用了索引

linux

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