天天看點

Oracle中檢視建立索引和使用索引的注意點

一、檢視和建立索引

select * from user_indexes where table_name = 'student'

create index i_student_num on student(num)

二、使用索引的注意點

①類型比對

若student中num列是varchar類型,語句select * from student where num = 100

該語句被轉化為select * from student where to_number(num) = 100,該列的索引就失效了。

②避免索引列參與計算 

索引失效:select * from student where num * 10 > 10000 

索引有效:select * from student where num > 10000 / 10

③不要對索引列使用is null或is not null

原則上對某一個列建立索引的時候,該列就不應該允許為空。

索引失效:select * from student where num is null