oracle rebuild table,oracle  alter table ..move 和alter table.. shrink space速度和存储需求比较...

实验在vmware虚拟机64位的solaris操作系统,10g release 2环境实现

本例中使用到用户tj,tj用户使用表空间usertest,并有无限的配额。

bash-3.00$ isainfo

-vk

64-bit amd64 kernel

modules

bash-3.00$ uname

-a

SunOS sunos 5.10

Generic_142910-17 i86pc i386 i86pc

bash-3.00$ sqlplus / as

sysdba

SQL*Plus: Release 10.2.0.1.0

- Production on Sun Jan 8 19:32:01 2012

Copyright (c) 1982, 2005,

Oracle. All

rights reserved.

Connected to:

Oracle Database 10g

Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP

and Data Mining options

Connected.

首先查看数据库存储使用情况,这里使用到了脚本tspace.sql ,脚本内容不做介绍

sys@DB01>

@tspace

Tablespace

Total Size

Free Size Pct

Free Pct

Used

FSFI

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

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

USERDATA

4096

4095.9375

100

0

82.77

SYSAUX

250

10.8125

4

96

67.79

USERS

5

2

40

60

100

SYSTEM

740

266.5625

36

64

100

UNDOTBS1

750

.1875

0

100

100

EXAMPLE

100

31.75

32

68

72.85

USERTEST

400

399.9375

100

0

100

7 rows selected.

Elapsed:

00:00:00.03

1.首先测试alter table .. move 命令

sys@DB01>

conn tj/tj

Connected.

tj@DB01>

select * from tab;

no rows

selected

Elapsed:

00:00:00.08

本例大表的创建借助了tom的脚本。

tj@DB01> get

big_table.sql

1 create table

big_table

2 as

3 select rownum id,

a.*

4

from all_objects a

5

where 1=0

6 /

7 alter table big_table

nologging;

8 declare

9

l_cnt number;

10

l_rows number := &1;

11 begin

12

insert

13

into big_table

14

select rownum, a.*

15

from all_objects a

16

where rownum <= &1;

17

l_cnt := sql%rowcount;

18

commit;

19

while (l_cnt < l_rows)

20

loop

21

insert into big_table

22

select rownum+l_cnt,

23

OWNER, OBJECT_NAME, SUBOBJECT_NAME,

24

OBJECT_ID, DATA_OBJECT_ID,

25

OBJECT_TYPE, CREATED, LAST_DDL_TIME,

26

TIMESTAMP, STATUS, TEMPORARY,

27

GENERATED, SECONDARY

28

from big_table

29

where rownum <= l_rows-l_cnt;

30

l_cnt := l_cnt + sql%rowcount;

31

commit;

32

end loop;

33 end;

34 /

35 alter table big_table

add constraint

36 big_table_pk primary

key(id)

37 /

38 begin

39

dbms_stats.gather_table_stats

40

( ownname

=> user,

41

tabname

=> 'BIG_TABLE',

42

method_opt => 'for all indexed columns',

43

cascade

=> TRUE );

44 end;

45 /

46* select count(*)

from big_table;

47

创建一个拥有2000000数据的大表

tj@DB01>

@big_table

Table created.

Elapsed:

00:00:00.55

Table

altered.

Elapsed:

00:00:00.05

Enter value for 1:

2000000

old

3:

l_rows number := &1;

new

3:

l_rows number := 2000000;

Enter value for 1:

2000000

old

9:

where rownum <= &1;

new

9:

where rownum <= 2000000;

PL/SQL procedure

successfully completed.

Elapsed:

00:00:07.59

Table altered.

Elapsed:

00:00:19.69

PL/SQL procedure

successfully completed.

Elapsed:

00:00:03.07

COUNT(*)

----------

2000000

Elapsed:

00:00:00.08

打开另外一个窗口,观察表空间使用的情况,计算big_table的大小

$ sqlplus / as

sysdba

SQL*Plus: Release 10.2.0.1.0

- Production on Sun Jan 8 19:02:32 2012

Copyright (c) 1982, 2005,

Oracle. All

rights reserved.

Connected to:

Oracle Database 10g

Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP

and Data Mining options

sys@DB01>

@tspace

Tablespace

Total Size

Free Size Pct

Free Pct

Used

FSFI

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

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

USERDATA

4096

4095.9375

100

0

82.77

SYSAUX

250

10.3125

4

96

82.55

USERS

5

2

40

60

100

SYSTEM

740

266.5625

36

64

100

UNDOTBS1

750

193.9375

26

74

75.82

EXAMPLE

100

31.75

32

68

72.85

USERTEST 400

132.9375

33

67

100

7 rows

selected.

sys@DB01>

select 400-133 from dual;

400-133

----------

267

表的大小是267M。

回到第一个窗口,删除表中不同位置的一些数据,模拟表碎片的状况

tj@DB01>

delete from big_table where id>=100000 and

id<=400000;

300001 rows

deleted.

Elapsed:

00:00:17.04

tj@DB01>

commit;

Commit complete.

Elapsed:

00:00:00.02

tj@DB01>

delete from big_table where id>=800000 and

id<=1200000;

400001 rows

deleted.

Elapsed:

00:01:03.56

tj@DB01>

delete from big_table where id>=1700000;

300001 rows

deleted.

Elapsed:

00:00:29.02

tj@DB01>

commit;

Commit complete.

Elapsed:

00:00:00.04

观察第二个窗口,看数据删除以后,表空间的存储使用情况。发现并没有什么变化,delete语句不会释放存储。

sys@DB01>

@tspace

Tablespace

Total Size

Free Size Pct

Free Pct

Used

FSFI

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

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

USERDATA

4096

4095.9375

100

0

82.77

SYSAUX

250

10.25

4

96

82.8

USERS

5

2

40

60

100

SYSTEM

740

266.5625

36

64

100

UNDOTBS1

750

1.4375

0

100

70.14

EXAMPLE

100

31.75

32

68

72.85

USERTEST

400

132.9375 33

67

100

7 rows selected.

执行alter table

..move命令,计算命令需要时间。

tj@DB01>

alter table big_table move;

Table

altered.

Elapsed:

00:00:18.85

在执行过程中,在第二个窗口观察,表空间使用情况

sys@DB01>

@tspace

Tablespace

Total Size

Free Size Pct

Free Pct

Used

FSFI

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

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

USERDATA

4096

4095.9375

100

0

82.77

SYSAUX

250

10.25

4

96

82.8

USERS

5

2

40

60

100

SYSTEM

740

266.5625

36

64

100

UNDOTBS1

750

1.3125

0

100

73.4

EXAMPLE

100

31.75

32

68

72.85

USERTEST

400

60.9375 15

85

100

7 rows

selected.

sys@DB01>

/

Tablespace

Total Size

Free Size Pct

Free Pct

Used

FSFI

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

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

USERDATA

4096

4095.9375

100

0

82.77

SYSAUX

250

10.25

4

96

82.8

USERS

5

2

40

60

100

SYSTEM

740

266.5625

36

64

100

UNDOTBS1

750

1.3125

0

100

73.4

EXAMPLE

100

31.75

32

68

72.85

USERTEST

400

12.9375

3

97

100

7 rows selected.

sys@DB01>

/

Tablespace

Total Size

Free Size Pct

Free Pct

Used

FSFI

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

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

USERDATA

4096

4095.9375

100

0

82.77

SYSAUX

250

10.25

4

96

82.8

USERS

5 2

40

60

100

SYSTEM

740

266.5625

36

64

100

UNDOTBS1

750

1.3125

0

100

73.4

EXAMPLE

100

31.75

32

68

72.85

USERTEST

400

12.9375

3

97

100

7 rows

selected.

sys@DB01>

/

Tablespace

Total Size

Free Size Pct

Free Pct

Used

FSFI

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

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

USERDATA

4096

4095.9375

100

0

82.77

SYSAUX

250

10.25

4

96

82.8

USERS

5

2

40

60

100

SYSTEM

740

266.5625

36

64

100

UNDOTBS1

750

1.3125

0

100

73.4

EXAMPLE

100

31.75

32

68

72.85

USERTEST

400

244.9375 61

39

81.84

7 rows selected.

sys@DB01>

select 400-244.9375 from dual;

400-244.9375

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

155.0625

通过以上一段查询结果我们发现,在执行move命令过程当中,表空间的空闲空间会越来越少,在本例中当剩余空间到12.9375时,move操作最终完成,并最终释放空间,表在执行move操作后,表的大小由267M缩小到155M(也就是说有267-155=112M的碎片空间)。

move操作的完成需要额外的表空间存储来实现,但这个大小并不是表的大小的1倍,而是根据表上的碎片空间来决定,碎片空间越大,需要的表空间上额外的空间就会越少。当然对于特别大的表,建议表做分区,对每个分区单独move这样时间和空间需求都可以进一步控制。

2.接下来测试alter table.. shrink space操作,要求表空间是ASSM管理。为了进行比较,所做的操作一致。

tj@DB01>

tj@DB01> drop

table big_table purge;

Table

dropped.

Elapsed:

00:00:02.76

tj@DB01>

@big_table

Table

created.

Elapsed:

00:00:00.20

Table

altered.

Elapsed:

00:00:00.03

Enter value for 1:

2000000

old

3:

l_rows number := &1;

new

3:

l_rows number := 2000000;

Enter value for 1:

2000000

old

9:

where rownum <= &1;

new

9:

where rownum <= 2000000;

PL/SQL procedure

successfully completed.

Elapsed:

00:00:08.97

Table

altered.

Elapsed:

00:00:15.88

PL/SQL procedure

successfully completed.

Elapsed:

00:00:03.46

COUNT(*)

----------

2000000

Elapsed:

00:00:00.07

在另外一个窗口观察,表的大小还是267M。

sys@DB01>

@tspace

Tablespace

Total Size

Free Size Pct

Free Pct

Used

FSFI

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

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

USERDATA

4096

4095.9375

100

0

82.77

SYSAUX

250

10.25

4

96

82.8

USERS

5

2

40

60

100

SYSTEM

740

266.5625

36

64

100

UNDOTBS1

750

1.1875

0

100

77.17

EXAMPLE

100

31.75 32

68

72.85

USERTEST

400

132.9375

33

67

100

7 rows

selected.

回到到第一个窗口,开始删除数据

tj@DB01> delete from big_table

where id>=100000 and

id<=400000;

300001 rows

deleted.

Elapsed:

00:00:19.81

tj@DB01>

delete from big_table where id>=800000 and

id<=1200000;

400001 rows

deleted.

Elapsed:

00:00:28.84

tj@DB01>

commit;

Commit

complete.

Elapsed:

00:00:00.03

tj@DB01>

delete from big_table where id>=1700000;

300001 rows

deleted.

Elapsed:

00:00:36.38

tj@DB01>

commit;

Commit complete.

Elapsed:

00:00:00.01

在第二个窗口观察,表空间没有任何变化

sys@DB01>

@tspace

Tablespace

Total Size

Free Size Pct

Free Pct

Used

FSFI

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

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

USERDATA

4096 4095.9375

100

0

82.77

SYSAUX

250

10.25

4

96

82.8

USERS

5

2

40

60

100

SYSTEM

740

266.5625

36

64

100

UNDOTBS1

750

1.1875

0

100

77.17

EXAMPLE

100

31.75

32

68

72.85

USERTEST

400

132.9375

33

67

100

7 rows

selected.

回到第一个窗口,执行shrink

space 操作,为了执行这个命令,首先把表的row

movement属性开启。

tj@DB01>

select table_name,row_movement from user_tables;

TABLE_NAME

ROW_MOVE

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

BIG_TABLE

DISABLED

Elapsed:

00:00:00.11

tj@DB01>

alter table big_table enable row movement;

Table altered.

Elapsed:

00:00:00.07

tj@DB01>

alter table big_table shrink space;

Table

altered.

Elapsed:

00:03:40.39

在第一个窗口执行命令的过程中,在第二个窗口观察表空间存储的变化

sys@DB01>

@tspace

Tablespace

Total Size

Free Size Pct

Free Pct

Used

FSFI

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

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

USERDATA

4096

4095.9375

100

0

82.77

SYSAUX

250

10.25

4

96

82.8

USERS

5

2

40

60

100

SYSTEM

740

266.5625

36

64

100

UNDOTBS1

750

90.3125

12

88

38.14

EXAMPLE

100

31.75

32

68

72.85

USERTEST

400

132.9375 33

67

100

7 rows

selected.

sys@DB01>

sys@DB01>

sys@DB01>

/

Tablespace

Total Size

Free Size Pct

Free Pct

Used

FSFI

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

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

USERDATA

4096

4095.9375

100

0

82.77

SYSAUX

250

10.25

4

96

82.8

USERS

5

2

40

60

100

SYSTEM

740

266.5625

36

64

100

UNDOTBS1

750

82.3125

11

89

37.49

EXAMPLE

100

31.75

32

68

72.85

USERTEST

400

132.9375

33

67

100

7 rows selected.

sys@DB01>

/

Tablespace

Total Size

Free Size Pct

Free Pct

Used

FSFI

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

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

USERDATA

4096

4095.9375

100

0

82.77

SYSAUX

250

10.25

4

96

82.8

USERS

5

2

40

60

100

SYSTEM

740

266.5625

36

64

100

UNDOTBS1

750

74.3125

10

90

36.69

EXAMPLE

100

31.75

32

68

72.85

USERTEST

400

132.9375 33

67

100

7 rows selected.

sys@DB01>

/

Tablespace

Total Size

Free Size Pct

Free Pct

Used

FSFI

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

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

USERDATA

4096

4095.9375

100

0

82.77

SYSAUX

250

10.25

4

96

82.8

USERS

5

2

40

60

100

SYSTEM

740

266.5625

36

64

100

UNDOTBS1

750

74.3125

10

90

36.69

EXAMPLE

100

31.75

32

68

72.85

USERTEST

400

132.9375

33

67

100

7 rows selected.

sys@DB01> /

Tablespace

Total Size

Free Size Pct

Free Pct

Used

FSFI

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

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

USERDATA

4096

4095.9375

100

0

82.77

SYSAUX

250

10.25

4

96

82.8

USERS

5

2

40

60

100

SYSTEM

740

266.5625

36

64

100

UNDOTBS1

750

.3125

0

100

100

EXAMPLE

100

31.75

32

68

72.85

USERTEST

400

254.5625 64

36

60.77

7 rows selected.

在以上的结果中,我们发现在命令执行过程当中,表的存储空间并没有任何变化,当命令执行完成后,存储空间释放。

综合以上分析,move操作需要使用额外的表空间存储,但是速度更快(本例中

Elapsed:

00:00:18.85)

shrink space操作,不需要任何额外的空间,但是速度要慢上很多(本例中

Elapsed:

00:03:40.39)

不建议在业务高峰时使用move和shrink space命令,move操作会锁住表,这样其他并发的用户在表上执行的DML语句会产生等待。shrink操作可以把他理解成内部的DML语句操作,所以不会对表生成排他锁(只在调整高水位线的时候会产生表的排他锁),其他用户的DML语句可以照常执行,建议如果非要在业务高峰期操作,为了不影响其他用户可以考虑使用

shrink space命令。

可以把shrink命令分解:

1.只压缩空间不调整水位线

在业务繁忙时可以执行。

alter table

big_table shrink space compact;

2.调整水位线 会产生锁,可以在业务比较少的时候执行,oracle 会记住1步骤中的操作,只调整水位线。

alter

table big_table shrink

space;

move命令会影响到表上的索引,索引需要rebuild。

shrink命令,oracle会维护索引,不用我们考虑。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、重建索引的前提 1、表上频繁发生update,delete操作; 2、表上发生了alter table ..move操作(move操作导致了rowid变化)。 二、重建索引的标准 1、索引重建是否有必要,一般看索引是否倾斜的严重,是否浪费了空间, 那应该如何才可以判断索引是否倾斜的严重,是否浪费了空间, 对索引进行结构分析(如下): SQL>Analyze index index_name validate structure; 2、在执行步骤1的session中查询index_stats表,不要到别的session去查询。 SQL>select height,DEL_LF_ROWS/LF_ROWS from index_stats; 说明:当 查询出来的 height>=4 或者 DEL_LF_ROWS/LF_ROWS>0.2 的场合 , 该索引考虑重建 。 举例: (t_gl_assistbalance 26 万多条信息 ) SQL> select count(*) from t_gl_assistbalance ; 输出结果: COUNT(*) ---------- 265788 SQL> Analyze index IX_GL_ASSTBAL_1 validate structure; Index analyzed SQL> select height,DEL_LF_ROWS/LF_ROWS from index_stats; 输出结果: HEIGHT DEL_LF_ROWS/LF_ROWS ---------- ------------------- 4 1 三、重建索引的方式 1、drop 原来的索引,然后再创建索引; 举例: 删除索引:drop index IX_PM_USERGROUP; 创建索引:create index IX_PM_USERGROUP on T_PM_USER (fgroupid); 说明:此方式耗时间,无法在24*7环境中实现,不建议使用。 2 、直接重建: 举例: alter index indexname rebuild; 或alter index indexname rebuild online; 说明:此方式比较快,可以在24*7环境中实现,建议使用此方式。 四、alter index rebuild 内部过程和注意点 alter index rebuildalter index rebuil online的区别 1、扫描方式不同 1.1、Rebuild以index fast full scan(or table full scan) 方式读取原索引中的数据来构建一个新的索引,有排序的操作; 1.2、rebuild online 执行表扫描获取数据,有排序的操作; 说明:Rebuild 方式 (index fast full scan or table full scan 取决于统计信息的cost) 举例1 SQL> explain plan for alter index IX_GL_ASSTBAL_1 rebuild; Explained SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT --------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | --------------------------------------------------------------------- | 0 | ALTER INDEX STATEMENT | | 999K| 4882K| 3219 | | 1 | INDEX BUILD NON UNIQUE| IDX_POLICY_ID2 | | | | | 2 | SORT CREATE INDEX | | 999K| 4882K| | | 3 | INDEX FAST FULL SCAN | IDX_POLICY_ID2 | 999K| 4882K| | --------------------------------------------------------------------- 举例2 SQL> explain plan for alter index idx_policy_id rebuild; Explained SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT --------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | --------------------------------------------------------------------- | 0 | ALTER INDEX STATEMENT | | 2072K| 9M| 461 | | 1 | INDEX BUILD NON UNIQUE| IDX_POLICY_ID | | | | | 2 | SORT CREATE INDEX | | 2072K| 9M| | | 3 | TABLE ACCESS FULL | TEST_INDEX | 2072K| 9M| 461 | 举例3 ( 注意和 举例1 比较 ) Rebuil online 方式 : SQL> explain plan for alter index idx_policy_id2 rebuild online; Explained SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT --------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | ---------------------------------------------------------------------| 0 | ALTER INDEX STATEMENT | | 999K| 4882K| 3219 | | 1 | INDEX BUILD NON UNIQUE| IDX_POLICY_ID2 | | | | | 2 | SORT CREATE INDEX | | 999K| 4882K| | | 3 | TABLE ACCESS FULL | TEST_INDEX2 | 999K| 4882K| 3219 | 2 、rebuild 会阻塞 dml 操作 ,rebuild online 不会阻塞 dml 操作 ; 3 、rebuild online 时系统会产生一个 SYS_JOURNAL_xxx 的 IOT 类型的系统临时日志表 , 所有 rebuild online 时索引的变化都记录在这个表中 , 当新的索引创建完成后 , 把这个表的记录维护到新的索引中去 , 然后 drop 掉旧的索引 ,rebuild online 就完成了。 注意点: 1、 执行rebuild操作时,需要检查表空间是否足够; 2、虽然说rebuild online操作允许dml操作,但是还是建议在业务不繁忙时间段进行; Rebuild操作会产生大量redo log ; 五、重建分区表上的分区索引 重建分区索引方法: Alter index indexname rebuild partition paritionname tablespace tablespacename; Alter index indexname rebuild subpartition partitioname tablespace tablespacename; Partition name 可以从user_ind_partitions查找 Tablepace 参数允许alter index操作更改索引的存储空间; 六、索引状态描述 在数据字典中查看索引状态,发现有三种: valid:当前索引有效 N/A :分区索引 有效 unusable:索引失效 七、术语 1、高基数:简单理解就是表中列的不同值多。 2、低基数:建单理解就是表中的列的不同值少。 3、以删除的叶节点数量:指得是数据行的delete操作从逻辑上删除的索引节点 的数量,要记住oracle在删除数据行后,将 “ 死 “ 节点保留在索引中,这样做可以加快sql删除操作的速度,因此oracle删除数据行后可以不必重新平衡索引。 4、索引高度:索引高度是指由于数据行的插入操作而产生的索引层数,当表中添加大量数据时,oracle将生成索引的新层次以适应加入的数据行,因此,oracle索引可能有4层,但是这只会出现在索引数中产生大量插入操作的区域。Oracle索引的三层结构可以支持数百万的项目,而具备4层或是更多层的需要重建。 5、每次索引访问的读取数:是指利用索引读取一数据行时所需要的逻辑I/O操作数,逻辑读取不必是物理读取,因为索引的许多内容已经保存在数据缓冲区,然而,任何数据大于10的索引都需要重建。 6、什么时候重建呢? 察看 dba_indexes 中的 blevel 。这列是说明索引从根块到叶快的级别,或是深度。如果级别大于等于4。则需要重建, 如下 :Select index_name,blevel from dba_indexes where blevel>=4. 另一个从重建中受益的指标显然是当该索引中的被删除项占总的项数的百分比。如果在20%以上时,也应当重建,如下 SQL>analyze index index_name validate structure SQL>select (del_lf_rows_len/lf_rows_len)*100 from index_stats where name= ’ index_name ’ 就能看到是否这个索引被删除的百分比。 7、什么样的重建方式更好? (1)、建索引的办法: 1.1、删除并从头开始建立索引。 1.2 、 使用 alter index index_name rebuild 命令重建索引。 1.3 、 使用 alter index index_name coalesce 命令重建索引。 (2)、下面讨论一下这三种方法的优缺点: 2.1、删除并从头开始建索引:方法是最慢的,最耗时的。一般不建议。 2.2、Alter index index_name rebuild 快速重建索引的一种有效的办法,因为使用现有索引项来重建新索引,如果客户操作时有其他用户在对这个表操作,尽量使用带online参数来最大限度的减少索引重建时将会出现的任何加锁问题,alter index index_name rebuild online。 但是,由于新旧索引在建立时同时存在,因此,使用这种技巧则需要有额外的磁盘空间可临时使用,当索引建完后把老索引删除,如果没有成功,也不会影响原来的索引。利用这种办法可以用来将一个索引移到新的表空间。 Alter index index_name rebuild tablespace tablespace_name 。 这个命令的执行步骤如下: 首先,逐一读取现有索引,以获取索引的关键字。 其次,按新的结构填写临时数据段。 最后,一旦操作成功,删除原有索引树,降临时数据段重命名为新的索引。 需要注意的是alter index index_name rebuild 命令中必须使用tablespace字句,以保证重建工作是在现有索引相同的表空间进行。 2.3、alter index index_name coalesce 使用带有coalesce参数时重建期间不需要额外空间,它只是在重建索引时将处于同一个索引分支内的叶块拼合起来,这最大限度的减少了与查询过程中相关的潜在的加锁问题,但是,coalesce选项不能用来将一个索引转移到其他表空间。 八、其他 1、truncate 分区操作和truncate 普通表的区别? 1.1、Truncate 分区操作会导致全局索引失效; truncate 普通表对索引没有影响; 1.2、Truncate 分区操作不会释放全局索引中的空间,而truncate 普通表会释放索引所占空间; 2、rename 表名操作对索引没有影响,因为rename操作只是更改了数据字典,表中数据行的rowid并没有发生变化 总结: 1、判断是否需要重建索引: SQL>analyze index index_name validate structure; SQL> select height,DEL_LF_ROWS/LF_ROWS from index_stats; ( 或 Select index_name,blevel from dba_indexes where blevel>=4 ); 说明 : 当查询出来的 height>=4 或者 DEL_LF_ROWS/LF_ROWS>0.2 的场合 , 该索引考虑重建 ; 2 、重建索引方法 : 方法一、 Alter index index_name rebuild tablespace tablespace_name; 优点:是快速重建索引的一种有效的办法,可以用来将一个索引移到新的表空间。 缺点:重建期间需要额外空间。 方法二、 alter index index_name coalesce; 优点:重建期间不需要额外空间。 缺点:coalesce选项不能用来将一个索引转移到其他表空间。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值