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'); 首页
上页
下页
尾页
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
[10]
[11]
[12]
[13]
[14]
[15]
[16]
[17]
[18]
[19]
[20]
[21]
[22]
[23]
[24]
[25]
[26]
[27]
[28]
[29]
[30]
[31]
[32]
[33]
[34]
[35]
[36]
[37]
[38]
[39]
[40]
[41]
[42]
[43]
[44]
[45]
[46]
[47]
[48]
[49]
[50]
[51]
[52]
[53]
[54]
[55]
[56]
[57]
[58]
[59]
[60]
[61]
[62]
本文关键:关于Oracle数据库中行迁移/行链接的问题
|