索引失效的情况有哪些?索引何时会失效?(全面总结)
共 4010字,需浏览 9分钟
·
2021-04-09 00:12
阅读本文大概需要 4 分钟。
来自:https://blog.csdn.net/bless2015/article/details/84134361
列与列对比
select * from test where id=c_id;
存在NULL值条件
select * from test where id is not null;
NOT条件
select * from test where id<>500;
select * from test where id in (1,2,3,4,5);
select * from test where not in (6,7,8,9,0);
select * from test where not exists (select 1 from test_02 where test_02.id=test.id);
LIKE通配符
select * from test where name like 张||'%';
条件上包括函数
select * from test where upper(name)='SUNYANG';
select * from test where name=upper('sunyang');
--INDEX RANGE SCAN
复合索引前导列区分大
select * from test where owner='sunyang';
数据类型的转换
select * from sunyang where id='123';
Connect By Level
谓词运算
select * from sunyang where id/2=:type_id;
select * from sunyang where id=:type_id*2;
Vistual Index
create index idx_test_id on test(id);
create index idx_test_id on test(id) nosegment;
CREATE TABLE test_1116(
id number,
a number
);
CREATE INDEX idx_test_1116_id on test_1116(id);
CREATE INDEX idx_test_1116_a on test_1116(a)nosegment;
begin
for i in 1 .. 100000 loop
insert into test_1116 values (i,i);
end loop;
commit;
end;
select count(id) from test_1116;
--第一次耗时:0.061秒
--第二次耗时:0.016秒
select count(a) from test_1116;
--第一次耗时:0.031秒
--第二次耗时:0.016秒
Invisible Index
alter index idx_test_id invisible;
alter index idx_test_id visible;
alter session set optimizer_use_invisible_indexes = true;
<END>
扫码加入技术交流群,不定时「送书」
推荐阅读:
能挣钱的,开源 SpringBoot 商城系统,功能超全,超漂亮,真TMD香!
最近面试BAT,整理一份面试资料《Java面试BATJ通关手册》,覆盖了Java核心技术、JVM、Java并发、SSM、微服务、数据库、数据结构等等。
朕已阅