詳談 Oracle 索引(筆記)

來源:互聯網
上載者:User

詳談 Oracle 索引(筆記)

1、Oracle索引空值問題

  當在有空值得列上建立單列索引時,如果搜尋條件為 is null 在解釋計劃中可以看到,對於此列oracle並沒有使用索引查詢;

  但是當建立的是多列索引是,就會按照索引來進行查詢。

2、B-樹索引

  :

  

在B-樹索引中,將會按照從上到下的順序進行索引。如果列的選擇度不低的話,索引掃描就會很慢。原因就在於要遍曆很多的葉子快來取出不同的行編號。

隨著出入資料的增多,最右側的葉子塊也在一直的增大,可能會導致緩衝區的繁忙等待。這種類型的最右側索引的快速增長被稱為 右側增長索引 。後面將談到一些解決方案。

3、位元影像索引

  位元影像索引不適合用於需要大量DML操作的表(DML指除select以外的SQL語句)。適合用於大多數資料具有較少的唯一的列進行的唯讀運算的資料倉儲表。

  位元影像索引要注意的一點是。更新一個具有位元影像索引的列,必須要更新位元影像索引。

4、分區索引

  4.1、局部索引

    局部索引使用LOCAL關鍵字來建立。

    create index index_name on table_name (column_name) local;

    當用到分區索引的時候,會直接尋找匹配分區的內容,而不是查詢每個分區。

  4.2、全域索引

    全域索引用GLOBAL來建立

  4.3、散列分區

    迴歸到B-數索引中所說到的右側增長索引問題,就可以用散列分區的方式來進行分區。

    與定界分割的方式不同散列分區是把所有的資料均勻的分布在不同的分區內。具體方法如下:

--定界分割 create table table2 partition by range( year ) (partition p_2012 values less than (2013), partition p_2013 values less than (2014), partition p_2014 values less than (2015), partition p_max values less than (maxvalue) ) as select * from table1;  --散列分區 drop sequence sf; create sequence sf cache 200; drop table table3;  create table table3 partition by hash(sid) partitions 32 as select sf.nextval sid,t.* from table1 t;  --通過以下代碼可以查到 select dbms_rowid.rowid_object(rowid) obj_id, count (*) from table3 group by dbms_rowid.rowid_object(rowid);      OBJ_ID  COUNT (*) ---------- ----------       86232      4717       86236      4571       86240      4696       86257      4633       86234      4547       86235      4580       86241      4717       86249      4589       86250      4612       86251      4623       86261      4742       86238      4578 ……  create unique index index_table3_sid on table3(sid) local ;  select * from table3_sid where sid =10000; --查看其解釋計劃,可以得到

 

 

5、壓縮索引

  壓縮索引是B-樹索引的一個變體,更適合於引導列中具有重複值的列

  create index index_name on table_name(column1,column2,column3) compress N;

  其中N為壓縮前幾項。例如N=2就是壓縮column1,column2這兩項索引。

  壓縮索引適用於引導列具有較少唯一值的索引。

6、基於函數的索引

  create create index index_name on table_name(function_name(column1));

  在select是必須加上function_name(column1)才能使用索引,只用column1的話,還是全表掃描。

7、反轉鍵索引

  也是一種解決右側增長索引問題的一種方法,但是因為索引是反轉的所以不能使用範圍運算子

  create index index_name on table_name (column_name) global reverse;

  不常用,因為會引起其他的一些負面影響

Oracle之索引(Index)執行個體講解 - 基礎 

Oracle | PL/SQL唯一索引(Unique Constraint)用法 

Oracle全文索引的效能優勢執行個體

Oracle非關鍵檔案恢複,redo、臨時檔案、索引檔案、密碼檔案

Oracle索引資料表空間資料檔案丟失及重建

Oracle 實現基於函數的索引

Oracle索引被抑制情況

Oracle 重建索引指令碼 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.