oracle 播布客 视频,播布客视频-Managing Indexes笔记

播布客视频第48-51讲:Chapter 12--Managing Indexes

一、index type

1. logical

single column & concatenated(符合index)

unique or nonunique

function-based

domain index(外部数据,oracle提供接口)

2. physical

partitioned or nonpartitoned

B-tree:Normal or reverse key

Bitmap

二、 B-tree index(Balance-tree index)平衡树index(1:1)

树形结构,平衡树会导致树的高度不会太高

root:the store info of data,一个范围值

branch:the store info of data一个范围值

leaf:block true data。双向链表

如:当select * from t where id>23 and id < 45

根据index最小值,从root节点找到leaf block,然后在leaf链表,做一次index range scan。即不再查找root节点,当找到第一个叶子节点时,进行index range scan

B-tree特点:index entry与data 一一对应。

leaf 级:index entry = index entry header + key column length + key column value + rowid

= 控制信息,多事物槽位控制 + index长度 + index值 + 指针(数据文件,数据块)

对表进行insert , delete时,oracle自动维护index,

index目的为了查询快,但是会导致insert,delete,update很慢。所以在保证查询性能达到一定级别的时候,尽可能的少用index。

三、 Bitmap index(distinct value very 少)

每一个叶子节点代表一个键值(distinct vale)

Bitmap index = key + start rowid + end rowid + bitmap

= distinct value + blockid.xx.fileid + blockid.xx.fileid + 二进制数值

四、 B-tree PK Bitmap

B-tree                                                   Bitmap

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

high-cardinality                                  low-cardinality

update on keys inexpensive           update to key columns very expensive

inefficitet for OR queries                 efficitet for OR queries

useful for OLTP                                useful for data warehousing or OLAP

五、 PCTFREE 30

block中的剩余空间<30时候,不可以再插入了,pctfree为了预留空间为了update语句

pctused在index中是没有用的。因为index是排序的。

六、 创建index的指导方针

1.需要根据具体业务逻辑,平衡查询和dml操作的需要

2.表和表的index需要放到不同的tablespace,因为table和index几乎是同时查询同时维护的。

3.最好使用一致性的extent size,e.g 5个块的整数倍 一次IO

4.考虑NOLOGGING for large indexes when create index.

5.INITRANS,允许对一个块中最多的并发事务个数,index的initrans>table的initrans值

七、 REBUILD INDEX

delete recode in table -> index标记已删除,但是不真实删除,除非100%的index entry都标记为删除,block才可用。

update recode in table -> index标记已删除,insert new index entry

所以会导致空间浪费,影响效率,需要rebuild,重新建立新的index。

offline index rebuild原理

1. lock the table(不能增删改)

2. create new temp index by reading old index

3. drop the old index

4. rename the temp index to original index

5. remove the table lock.

online index rebuild原理

1. lock the table

2. create new temp and empty index and an IOT to stroe on-going DML

3. Release the table lock;

4. create new temp index by reading old index

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

6. lock the table

7. final merge from IOT and drop the old index

8. rename the temp index to original index

9. remove the table lock.

rebuild index 情况

1. move to diff tablespace

2. index contains many deleted entries.

3. an existing normal index must be converted into a reverse key index.

4. the table has been moved to another tablespace,need rebuild index

八、 COALESCING INDEX

ALTER INDEX XXX COALESCE;

合并空余空间

1. Scan alone the base(leaf) of the index.

2. where adjacent nodes(相邻的节点) can be combined into a single node.

通常来说COALESCING INDEX比REBUILD INDEX 要快,但是他们的场合还需要具体问题具体分析。

1. 如果index中90%的好的,只有10%是碎片,所以可以考虑用COALESCING INDEX

2. 如果index已经支离破碎了,几乎每个叶节点的block都有碎片的话,那么就需要用REBUILD INDEX

九、 CHECKING INDEX VALIDITY

AYALYZE INDEX XXX VALIDATE STRUCTURE;

分析index的有效性,然后把结果放到INDEX_STATS表中

select height, name , lf_rows, lf_blks, del_lf_rows from index_stats

如果DEL_LF_ROWS/LF_ROWS>=15%,可能需要重建index

十、 DROP INDEXES

DROP INDEX XXX

删除index的情况:

1. 往表里面批量imp数据前,需要先删除index,然后imp,然后create index

2. drop 不经常使用的index

3. drop and re-create invalid index

index rebulid 的速度快于 drop and re-create index ,因为前者是读old index,后者是从数据表中读取数据。

十一、 Identifying Unused index

ALTER INDEX XXX   MONITORING USAGE;--v$object_usage

ALTER INDEX XXX NOMONITORING USAGE;

select * from v$object_usage;

十二、Getting index information            1. DBA_INDEXES

2. DBA_IND_COLUMNS

3. v$object_usage

参考链接:

播布客视频第48-51讲:Chapter 12--Managing Indexes

一、index type

1. logical

single column & concatenated(符合index)

unique or nonunique

function-based

domain index(外部数据,oracle提供接口)

2. physical

partitioned or nonpartitoned

B-tree:Normal or reverse key

Bitmap

二、 B-tree index(Balance-tree index)平衡树index(1:1)

树形结构,平衡树会导致树的高度不会太高

root:the store info of data,一个范围值

branch:the store info of data一个范围值

leaf:block true data。双向链表

如:当select * from t where id>23 and id < 45

根据index最小值,从root节点找到leaf block,然后在leaf链表,做一次index range scan。即不再查找root节点,当找到第一个叶子节点时,进行index range scan

B-tree特点:index entry与data 一一对应。

leaf 级:index entry = index entry header + key column length + key column value + rowid

= 控制信息,多事物槽位控制 + index长度 + index值 + 指针(数据文件,数据块)

对表进行insert , delete时,oracle自动维护index,

index目的为了查询快,但是会导致insert,delete,update很慢。所以在保证查询性能达到一定级别的时候,尽可能的少用index。

三、 Bitmap index(distinct value very 少)

每一个叶子节点代表一个键值(distinct vale)

Bitmap index = key + start rowid + end rowid + bitmap

= distinct value + blockid.xx.fileid + blockid.xx.fileid + 二进制数值

四、 B-tree PK Bitmap

B-tree                                                   Bitmap

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

high-cardinality                                  low-cardinality

update on keys inexpensive           update to key columns very expensive

inefficitet for OR queries                 efficitet for OR queries

useful for OLTP                                useful for data warehousing or OLAP

五、 PCTFREE 30

block中的剩余空间<30时候,不可以再插入了,pctfree为了预留空间为了update语句

pctused在index中是没有用的。因为index是排序的。

六、 创建index的指导方针

1.需要根据具体业务逻辑,平衡查询和dml操作的需要

2.表和表的index需要放到不同的tablespace,因为table和index几乎是同时查询同时维护的。

3.最好使用一致性的extent size,e.g 5个块的整数倍 一次IO

4.考虑NOLOGGING for large indexes when create index.

5.INITRANS,允许对一个块中最多的并发事务个数,index的initrans>table的initrans值

七、 REBUILD INDEX

delete recode in table -> index标记已删除,但是不真实删除,除非100%的index entry都标记为删除,block才可用。

update recode in table -> index标记已删除,insert new index entry

所以会导致空间浪费,影响效率,需要rebuild,重新建立新的index。

offline index rebuild原理

1. lock the table(不能增删改)

2. create new temp index by reading old index

3. drop the old index

4. rename the temp index to original index

5. remove the table lock.

online index rebuild原理

1. lock the table

2. create new temp and empty index and an IOT to stroe on-going DML

3. Release the table lock;

4. create new temp index by reading old index

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

6. lock the table

7. final merge from IOT and drop the old index

8. rename the temp index to original index

9. remove the table lock.

rebuild index 情况

1. move to diff tablespace

2. index contains many deleted entries.

3. an existing normal index must be converted into a reverse key index.

4. the table has been moved to another tablespace,need rebuild index

八、 COALESCING INDEX

ALTER INDEX XXX COALESCE;

合并空余空间

1. Scan alone the base(leaf) of the index.

2. where adjacent nodes(相邻的节点) can be combined into a single node.

通常来说COALESCING INDEX比REBUILD INDEX 要快,但是他们的场合还需要具体问题具体分析。

1. 如果index中90%的好的,只有10%是碎片,所以可以考虑用COALESCING INDEX

2. 如果index已经支离破碎了,几乎每个叶节点的block都有碎片的话,那么就需要用REBUILD INDEX

九、 CHECKING INDEX VALIDITY

AYALYZE INDEX XXX VALIDATE STRUCTURE;

分析index的有效性,然后把结果放到INDEX_STATS表中

select height, name , lf_rows, lf_blks, del_lf_rows from index_stats

如果DEL_LF_ROWS/LF_ROWS>=15%,可能需要重建index

十、 DROP INDEXES

DROP INDEX XXX

删除index的情况:

1. 往表里面批量imp数据前,需要先删除index,然后imp,然后create index

2. drop 不经常使用的index

3. drop and re-create invalid index

index rebulid 的速度快于 drop and re-create index ,因为前者是读old index,后者是从数据表中读取数据。

十一、 Identifying Unused index

ALTER INDEX XXX   MONITORING USAGE;--v$object_usage

ALTER INDEX XXX NOMONITORING USAGE;

select * from v$object_usage;

十二、Getting index information            1. DBA_INDEXES

2. DBA_IND_COLUMNS

3. v$object_usage

参考链接:

你可能感兴趣的:(oracle,播布客,视频)