Oracle管理索引(二)Oracle管理索引基本概念

來源:互聯網
上載者:User

1、索引的概念

索引是用於加速資料存取的資料庫物件。合理地使用索引可以大大降低I/O次數。

2、索引的功能:對記錄進行排序,加快表的查詢速度。

3、索引的分類:

(1)單列索引和複合索引

單列索引是基於單個列所建立的索引;複合索引時基於兩列或多列所建立的索引。

SQL>CREATE    INDEX    emp_idx1   on  emp( ename, job);

SQL>CREATE    INDEX    emp_idx2   on   emp (job  , ename);

可以在相同列上建立不同的索引,列順序不一致即可

(2)惟一索引和非唯一性索引

惟一索引是索引列值不能重複的索引;非惟一索引時索引列值可以重複的索引。

無論是惟一索引還是非惟一索引,索引都允許null;

當定義主鍵約束或惟一約束時,Oracle會自動在相應的約束列上建立惟一索引。

(3)B-tree 索引和位元影像索引

(a) B-tree 索引(預設)

a、在一個大表上

b、建立在重複值比較少的列上 ,在做select查詢時,返回記錄的行數小於全部記錄的4%

c、如果這一列經常用來做where子句和排序,也可以用來建立索引

d、一般用於OLTP

(b)bitmap 索引

a、建立在重複值非常高的列上

b、 在做DML 操作時,代價值比較高

c、一般用於OLAP 或DSS

注意: B-tree 索引不能使用or串連的語句,bitmap index可以使用

4、建立索引:預設建立B-tree index

5、建立索引資料表空間

建議建立專門的索引資料表空間去存放索引,便於管理。

SQL> conn /as sysdba

Connected.

SQL> create tablespace indexes

2  datafile '/u01/app/oracle/oradata/anny/index01.dbf' size 100m

3  autoextend on next 10m maxsize 500m

4  extent management local uniform size 128k;

Tablespace created.

SQL> select file_id,file_name,tablespace_name from dba_data_files;

FILE_ID FILE_NAME                                          TABLESPACE_NAME

---------- -------------------------------------------------- ---------------

5 /u01/app/oracle/oradata/anny/text01.dbf            TEXT

4 /u01/app/oracle/oradata/anny/user01.dbf            USERS

3 /u01/app/oracle/oradata/anny/sysaux01.dbf          SYSAUX

2 /u01/app/oracle/oradata/anny/lx02.dbf              LX02

1 /u01/app/oracle/oradata/anny/system01.dbf          SYSTEM

6 /u01/app/oracle/oradata/anny/lx01.dbf              LX01

7 /u01/app/oracle/oradata/anny/undotbs01.dbf         UNDOTBS

8 /u01/app/oracle/oradata/anny/lx03.dbf              LX03

9 /u01/app/oracle/oradata/anny/lx04.dbf              LX04

10 /u01/app/oracle/oradata/anny/index01.dbf           INDEXES

10 rows selected.

6、與索引有關的視圖

DBA_INDEXES

DBA_IND_COLUMNS

V$OBJECT_USAGE

查看本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/database/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.