您的位置:首页 > 数据库 > Oracle

ORACLE_基础十(index)

2015-04-04 21:46 239 查看

Classification of Indexes

1.Logical:

a.Single columne or concatenated

b.Unique or nonunique

c.Function-based

d.Domain

2.Physical:

a. Partitioned or nonpartitioned

b.B-tree:Normal or reverse key

c. Bitmap





B-Tree VS Bitmap

B-tree Bitmap

Suitable for high-cardinality columns Suitable for low-cardinality columns

Updates on keys relatively inexpensive Updates to key columns very expensive

Inefficient for queries using OR predicates Efficient for queries using OR predicats

Useful for OLTP Useful for data warehousing

Creating B-Tree Indexes

CREATE INDEX hr.employees_last_name_idx ON hr.employees(last_name) PCTFREE 30 STORAGE(INITAIL 200K NEXT 200K PCTINCREASE 0 MAXEXTENTS 50 ) TABLESPACE index


Creating Indexes:Guidelines

1.Balance query and DML needs

2.Place in separate tablespace.

3.Use uniform extent sizes: Multiples of five blocks or MINIMUM ExTENT size for tablespace

4.Consider NOLOGGING for large indexs

5.INITRANS should generally be higher on indexes than on the corresponding tables.

Storage Params for Indexes

ALTER INDEX emplyees_last_name_idx STORAGE(NEXT 400K MAXExTENTS 100);


Alloc & Dealloc Index Space

ALTER INDEX orders_region_id_idx ALLOCATE EXTENT(SIZE 200K DATAFILE '/DISK6/index01.dbf');
ALTER INDEX order_id_idx DEALLOCATE UNUSED


Rebuilding Indexes

Use the ALTER INDEX command to :

1.Move an idnex to a different tablespace

2.Improve space utilization by removing deleted entries

ALTER INDEX orders_region_id_idx REBUILD TABLESPACE index02;


Offline Index Rebuild

1.Lock the table

2.Create a new , temporary index by reading against the contents of the existing index

3.Drops the original index

4.Renames the temporary index tomake it seem to be the original index

5.Remove the table lock



Rebuilding Indexes Online

Indexes can be rebuilt with minimal table locking

ALTER INEX order_id_idx REBUILD ONLINE


1.Lock the table

2.Create a new , temporary and empty index and an IOT to store on-going DML

3.Release the table lock

4.Populate the temporary index by reding against the contentts of the existing index.

5.Merge contents of the IOT in with the new index

6.Lock the table

7.Final merge from IOT and drop the original index

8.Renames the temporary index tomake it seem to be the original index

9.Remove the table lock.

Coalescing indexes

Checking Index Validity

ANALYZE INDEX orders_region_id_idx VALIDATE STRUCTURE



SELECT height,name,lf_rows,lf_blks,del_lf_rows FROM index_stats;

Dropping Indexes

1.Drop and re-create an index before bulk loads

2.Drop indexes that are infrequently needed, and build indexes when nexessary

3.Drop and re-create invalid indexes

DROP INDEX hr.departments_name_idx


Identifying Unused Indexes

1.To start monitoring the usage of an index:

ALTER INDEX ht.dept_id_idx MONITORING USAGE

2. To stop monitoring the useage of an index

ALTER INDEX hr.dept_id_idx NOMONITORING USAGE

结果在:

select * from v$object_usage;

Getting Index Information

DBA_INDEXES: provides information on the indexes

DBA_IND_COLUMNS: provides information on the columns indexed

V$OBJECT_USAGE: Provides information on the usage of an inde


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: