关于Oracle数据库中行迁移/行链接的问题[15]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 coolyl 的 blog

5.  从临时表中取出并重新插入那些被删除了的数据到原来的表中,并删除临时表。

insert  into  table_name  select  *  from  table_name_temp;

drop  table  table_name_temp;

对于这种传统的清除rm的方法,优点是执行起来过程比较简单,容易实现。但是这种算法的缺陷是没有考虑到表关联的情况,在大多数数据库中很多表都是和别的表之间有表关联的,有外键的限制,这样就造成在步骤3中根本无法delete掉存在有行迁移的记录行,所以这种方法能够适用的表的范围是有限的,只能适用于表上无任何外键关联的表。由于这种方法在插入和删除数据的时候都没有disable掉索引,这样导致主要消耗时间是在删除和插入时维持索引树的均衡上了,这个对于如果记录数不多的情况时间上还比较短,但是如果对于记录数很多的表这个所消耗的时间就不是能够接受的了。显然,这种方法在处理大数据量的表的时候显然是不可取的。

以下是一个具体在生产数据库上清除行迁移的例子,在这之前已经调整过表的pctfree参数至一个合适的值了:

sql>@$oracle_home/rdbms/admin/utlchain.sql

table created.

sql> analyze table customer list chained rows into chained_rows;

table analyzed.

sql>select count(*) from chained_rows

table_name                       count(*)

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

customer                            21306

1 rows selected.

查看在customer表上存在的限制:

sql>select constraint_name,constraint_type,table_name from user_constraints where table_name='customer';

constraint_name                c table_name

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

pk_customer1                   p customer

sql>select constraint_name,constraint_type,table_name from user_constraints where r_constraint_name='pk_customer1';

no rows selected

sql> create  table  customer_temp  as

select  *  from  customer   where  rowid  in

(select  head_rowid  from  chained_rows

where  table_name  =  'customer');

本文关键:关于Oracle数据库中行迁移/行链接的问题
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top