版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xxzhaobb/article/details/82224510
今天看12c的官方文档,提到了索引的COALESCE。
官方文档有关于索引的重建和合并的对比
合并的示例
以下是测试的过程
测试的时候,参考了文档 https://www.linuxidc.com/Linux/2015-04/115663.htm
创建表及索引
create table t as select * from dba_objects ;
create index idx_t_id on t(object_id);
进行模拟,删除大部分数据
select max(object_id) from t;
C##BB@win12c>select max(object_id) from t;
MAX(OBJECT_ID)
--------------
73463
delete t where object_id<73463;
commit;
收集统计信息
exec dbms_stats.gather_table_stats('C##BB','T',cascade=>true);
查看表段,索引段的信息
SQL> select EXTENT_ID, FILE_ID, BLOCK_ID, BYTES, BLOCKS from dba_extents where owner='C##BB' and segment_name='T';
EXTENT_ID FILE_ID BLOCK_ID BYTES BLOCKS
---------- ---------- ---------- ---------- ----------
0 7 248 65536 8
1 7 256 65536 8
2 7 264 65536 8
3 7 272 65536 8
4 7 280 65536 8
5 7 288 65536 8
6 7 296 65536 8
7 7 304 65536 8
8 7 440 65536 8
9 7 448 65536 8
10 7 456 65536 8
11 7 464 65536 8
12 7 472 65536 8
13 7 480 65536 8
14 7 488 65536 8
15 7 496 65536 8
16 7 512 1048576 128
17 7 640 1048576 128
18 7 768 1048576 128
19 7 896 1048576 128
EXTENT_ID FILE_ID BLOCK_ID BYTES BLOCKS
---------- ---------- ---------- ---------- ----------
20 7 1024 1048576 128
21 7 1152 1048576 128
22 7 1280 1048576 128
23 7 1408 1048576 128
24 7 1536 1048576 128
25 7 1664 1048576 128
26 7 1792 1048576 128
27 rows selected
SQL> select EXTENT_ID, FILE_ID, BLOCK_ID, BYTES, BLOCKS from dba_extents where owner='C##BB' and segment_name='IDX_T_ID';
EXTENT_ID FILE_ID BLOCK_ID BYTES BLOCKS
---------- ---------- ---------- ---------- ----------
0 7 168 65536 8
1 7 176 65536 8
2 7 184 65536 8
3 7 192 65536 8
4 7 312 65536 8
5 7 320 65536 8
6 7 328 65536 8
7 7 336 65536 8
8 7 344 65536 8
9 7 352 65536 8
10 7 360 65536 8
11 7 368 65536 8
12 7 376 65536 8
13 7 384 65536 8
14 7 392 65536 8
15 7 400 65536 8
16 7 1920 1048576 128
17 rows selected
对索引进行分析,并查看索引的统计
analyze index idx_t_id validate structure;
select height, blocks, lf_rows, lf_blks, lf_rows_len, lf_blk_len, br_rows, br_blks, del_lf_rows from index_stats;
C##BB@win12c>select height, blocks, lf_rows, lf_blks, lf_rows_len, lf_blk_len, br_rows, br_blks, del_lf_rows from index_stats;
HEIGHT BLOCKS LF_ROWS LF_BLKS LF_ROWS_LEN LF_BLK_LEN BR_ROWS BR_BLKS DEL_LF_ROWS
---------- ---------- ---------- ---------- ----------- ---------- ---------- ---------- -----------
2 256 72631 161 1151278 8000 160 1 72630
C##BB@win12c>
进行索引的合并
alter index idx_t_id coalesce;
再次查看索引段的情况,没有变化
C##BB@win12c>select EXTENT_ID, FILE_ID, BLOCK_ID, BYTES, BLOCKS from dba_extents where owner='C##BB' and segment_name='IDX_T_ID';
EXTENT_ID FILE_ID BLOCK_ID BYTES BLOCKS
---------- ---------- ---------- ---------- ----------
0 7 168 65536 8
1 7 176 65536 8
2 7 184 65536 8
3 7 192 65536 8
4 7 312 65536 8
5 7 320 65536 8
6 7 328 65536 8
7 7 336 65536 8
8 7 344 65536 8
9 7 352 65536 8
10 7 360 65536 8
EXTENT_ID FILE_ID BLOCK_ID BYTES BLOCKS
---------- ---------- ---------- ---------- ----------
11 7 368 65536 8
12 7 376 65536 8
13 7 384 65536 8
14 7 392 65536 8
15 7 400 65536 8
16 7 1920 1048576 128
已选择 17 行。
分析索引的结果,并查看索引的统计,发现索引被合并了
analyze index idx_t_id validate structure;
select height, blocks, lf_rows, lf_blks, lf_rows_len, lf_blk_len, br_rows, br_blks, del_lf_rows from index_stats;
C##BB@win12c>select height, blocks, lf_rows, lf_blks, lf_rows_len, lf_blk_len, br_rows, br_blks, del_lf_rows from index_stats;
HEIGHT BLOCKS LF_ROWS LF_BLKS LF_ROWS_LEN LF_BLK_LEN BR_ROWS BR_BLKS DEL_LF_ROWS
---------- ---------- ---------- ---------- ----------- ---------- ---------- ---------- -----------
2 256 1 1 16 8000 0 1 0
C##BB@win12c>
ENd