索引失效的情況有哪些?索引何時會失效?(全面總結)
閱讀本文大概需要 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 張||'%';
條件上包括函數(shù)
select * from test where upper(name)='SUNYANG';
select * from test where name=upper('sunyang');
--INDEX RANGE SCAN
復合索引前導列區(qū)分大
select * from test where owner='sunyang';
數(shù)據(jù)類型的轉換
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>
掃碼加入技術交流群,不定時「送書」
推薦閱讀:
又漲了!2021 年 3 月程序員工資統(tǒng)計新出爐
能掙錢的,開源 SpringBoot 商城系統(tǒng),功能超全,超漂亮,真TMD香!
最近面試BAT,整理一份面試資料《Java面試BATJ通關手冊》,覆蓋了Java核心技術、JVM、Java并發(fā)、SSM、微服務、數(shù)據(jù)庫、數(shù)據(jù)結構等等。
朕已閱 

