oracle index的5種使用模式

2021-08-25 18:09:21 字數 2019 閱讀 5245

索引的使用對資料庫的效能有巨大的影響。

共有五類不同的使用模式。

1。index unique scan    效率最高,主鍵或唯一索引

2。index full scan      有順序的輸出,不能並行讀索引

3。index fast full scan  讀的最塊,可以並行訪問索引,但輸出不按順序

4。index range scan      給定的區間查詢

5。index skip scan       聯合索引,不同值越少的列,越要放在前面

--實驗後的總論。

能用唯一索引,一定用唯一索引

能加非空,就加非空約束

一定要統計表的資訊,索引的資訊,柱狀圖的資訊。

聯合索引的順序不同,影響索引的選擇,盡量將值少的放在前面

只有做到以上四點,資料庫才會正確的選擇執行計畫。

conn system/manager

grant select any dictionary to scott;

conn scott/tiger

drop table t1 purge;

create table t1 as select * from dba_objects;

analyze table t1 compute statistics;

create index it1 on t1(object_type);

set autot traceonly

select distinct object_type from t1;

將是全表掃瞄,為什麼不使用索引呢?因為索引中不能含有null值,

如果使用索引就可能產生不正確的結果。

--增加非空約束

alter table t1 modify (object_type not null);

select distinct object_type from t1  ;

使用index fast full scan方式查詢資料

-- select  object_type from t1;

使用index fast full scan,因為不需要排序

select  object_type from t1 order by 1;

使用index full scan,因為要按照順序輸出

select  object_type from t1 where object_type='table';

使用index range scan

--使用非唯一索引

create index i2t1 on t1(object_id);

select * from t1 where object_id=3762;

使用index range scan,因為資料庫不知道是否唯一

--使用唯一索引

drop index i2t1;

create unique index i2t1 on t1(object_id);

使用index unique scan,因為資料庫知道是唯一的

--跳躍的掃瞄索引

create index i3t1 on t1(object_type,object_name);

select * from t1 where object_name='emp';

select object_name from t1 where object_name='emp';

使用index skip scan,因為資料庫知道可以跳過object_type,雖然object_name在第二個列。

--聯合索引的順序不同,影響索引的選擇,盡量將值少的放在前面

drop index i3t1;

drop index it1;

create index i3t1 on t1(object_name,object_type);

select * from t1 where object_type='table';

計畫為全表掃瞄。

TabWidget TabHost的兩種使用方法

android tabwidget tabhost有兩種使用方法 第一種 使用系統自帶寫好的tabhost 及繼承自tabactivity類 具體 如下 package com.aina.android import android.content.dialoginte ce import andr...

的5種用法

是補格助詞 和動詞 組合形成的,是修飾性慣用型,也有人稱作 形式用言 這一類詞雖然不是乙個單詞,但是在句中有固定的幾種含義,應該有明確的概念。今天就給大家分享 的5種用法。一 體言 表示身分 地位 資格 立場 種類 作用等,翻譯為 作為 以 身分 等等,在句子中做狀語 例句 趣味 日本語 勉強 作為...

PyQt5中QTableWidget的使用方法

為了在螢幕上顯示更多的控制項,我們使用qwidget來作為乙個容器,下面列出了乙個方法表 qwidget 建立用於顯示控制項的視窗 addtab self,qwidget,str qwiget 需要新增的控制項 str tab標題 settabtext self,int,str int 控制項序號 ...