資料庫索引 索引失效

2021-09-19 05:37:13 字數 777 閱讀 2875

以下情況不走索引:

select * from student where name like '%xiaoyao';
select * from student where not (score=100);

select * from student where score <> 100;

select * from student where score != 100;

select * from student where score not in (80,90,100);

--not exist也不走索引

select * from student where dept_id = 1

--應該使用:

select * from student where dept_id = '1'

--student表內name建立了索引,***沒有建索引

select * from student where name = 'zhangsan' or *** = 1

--建立組合索引(key1,key2);

select * from key1 = 1;--組合索引有效;

select * from key1 = 1 and key2= 2;--組合索引有效;

select * from key2 = 2;--組合索引失效;不符合最左字首原則

資料庫索引失效

索引失效 1 沒有查詢條件,或者查詢條件沒有建立索引 2 在查詢條件上沒有使用引導列 3 查詢的數量是大表的大部分,應該是30 以上。4 索引本身失效 5 查詢條件使用函式在索引列上 見12 6 對小表查詢 7 提示不使用索引 8 統計資料不真實 9 cbo計算走索引花費過大的情況。其實也包含了上面...

資料庫索引失效

作資料庫索引能起到優化資料庫查詢,提高查詢效率的作用。並且對也稍微大一點的資料量的服務來說,索引的建立是必須的,也是關鍵的。但是索引也要合理應用,不要遇到查詢就建索引,也不能亂建。如果造成索引失效那還不如不建。索引失效有的時候是因為自己的語句問題造成的。下面是幾種造成索引失效的幾種原因,一 以下的方...

資料庫索引失效情況

索引失效 1.建立了單字段索引,where條件內多個字段alter table test add index test index name using btree select from test where name test and 02.建立聯合索引,where條件單個字段alter tab...