alter index coalesce和alter index rebuild的区别

alter index coalesce和alter index rebuild的区别:
alter index coalesce是合并同一branch的leaf block。
而alter index rebuild是重新建立一个indexes,一般需要2倍的index大小的空间。而且需要排序。
以下是证明alter index coalesce的过程:
×××××××× ×××××××××××××××××alter index coalesce××××××××××××××××××××××
SQL>
SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------

Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
PL/SQL Release 9.2.0.6.0 - Production
CORE    9.2.0.6.0       Production
TNS for Solaris: Version 9.2.0.6.0 - Production
NLSRTL Version 9.2.0.6.0 - Production

SQL> drop table t2;

Table dropped.

SQL> create table t2(col1 number);

Table created.

SQL> create unique index t2_inx on t2(col1);

Index created.

SQL> alter table t2 add constraint t2_pk primary key(col1);

Table altered.

SQL> begin
  2  for i in  500001..601000 loop
  3      insert into t2 values(i);
  4  end loop;
  5  end;
  6  /

PL/SQL procedure successfully completed.

SQL> commit;

Commit complete.

SQL> begin
  2  sys.dbms_stats.gather_table_stats('SYSTEM', 'T2', ESTIMATE_PERCENT => 20, c
ascade=> true);
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL> col index_name for a10;
SQL> select index_name, blevel, leaf_blockS, distinct_keys
  2       clustering_factor, num_rows
  3       from user_indexes
  4       where table_name LIKE 'T2%';

INDEX_NAME     BLEVEL LEAF_BLOCKS CLUSTERING_FACTOR   NUM_ROWS
---------- ---------- ----------- ----------------- ----------
T2_INX              1         190            101000     101000

SQL> declare
  2  cursor mm is select col1 from t2;
  3  begin
  4  for cur_1 in mm loop
  5     if mod(cur_1.col1, 2) = 0 then
  6       delete from t2 where col1=cur_1.col1;
  7     end if;
  8  end loop;
  9  commit;
 10  end;
 11  /

PL/SQL procedure successfully completed.

SQL> begin
  2  sys.dbms_stats.gather_table_stats('SYSTEM', 'T2', ESTIMATE_PERCENT => 20, c
ascade=> true);
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL> select index_name, blevel, leaf_blockS, distinct_keys
  2       clustering_factor, num_rows
  3       from user_indexes
  4       where table_name LIKE 'T2%';

INDEX_NAME     BLEVEL LEAF_BLOCKS CLUSTERING_FACTOR   NUM_ROWS
---------- ---------- ----------- ----------------- ----------
T2_INX              1         190             50500      50500

SQL> alter index t2_inx coalesce;

Index altered.

SQL> begin
  2  sys.dbms_stats.gather_table_stats('SYSTEM', 'T2', ESTIMATE_PERCENT => 20, c
ascade=> true);
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL> select index_name, blevel, leaf_blockS, distinct_keys
  2       clustering_factor, num_rows
  3       from user_indexes
  4       where table_name LIKE 'T2%';

INDEX_NAME     BLEVEL LEAF_BLOCKS CLUSTERING_FACTOR   NUM_ROWS
---------- ---------- ----------- ----------------- ----------
T2_INX              1         189             50500      50500

SQL> declare
  2  cursor mm is select col1 from t2;
  3  begin
  4  for cur_1 in mm loop
  5     if mod(cur_1.col1, 3) = 0 then
  6       delete from t2 where col1=cur_1.col1;
  7     end if;
  8  end loop;
  9  commit;
 10  end;
 11  /

PL/SQL procedure successfully completed.

SQL> alter index t2_inx coalesce;

Index altered.

SQL> begin
  2  sys.dbms_stats.gather_table_stats('SYSTEM', 'T2', ESTIMATE_PERCENT => 20, c
ascade=> true);
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL> select index_name, blevel, leaf_blockS, distinct_keys
  2       clustering_factor, num_rows
  3       from user_indexes
  4       where table_name LIKE 'T2%';

INDEX_NAME     BLEVEL LEAF_BLOCKS CLUSTERING_FACTOR   NUM_ROWS
---------- ---------- ----------- ----------------- ----------
T2_INX              1          95             33666      33666

SQL>

×××××××× ×××××××××××××××××alter index coalesce××××××××××××××××××××××

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值