模拟并消除行迁移(Row Migration)

--什么是行迁移?
A situation in which Oracle Database moves a row from one data block to another data block because the row grows too large to fit in the original block.


注:尽管行迁移与行链接是两个不同的事情,但是在oracle内部,它们被当作一回事。所以当你检测行迁移与行链接时,你应该仔细的分析当前你正在处理的是行迁移还是行链接。


--模拟实验
EODA@PROD1> create table t(x int, y varchar2(50));

Table created.

EODA@PROD1> begin
  2  for i in 1..1000 loop
  3    insert into t values (i,'A');
  4  end loop;
  5  commit;
  6  end;
  7  /

PL/SQL procedure successfully completed.

EODA@PROD1> analyze table t compute statistics;

Table analyzed.

--chain_cnt计算了存在行迁移和行链接的行数
EODA@PROD1> select table_name,num_rows,chain_cnt from user_tables where table_name='T';

TABLE_NAME			 NUM_ROWS  CHAIN_CNT
------------------------------ ---------- ----------
T				     1000	   0

EODA@PROD1> update t set y=rpad('A',50,'B');

1000 rows updated.

EODA@PROD1> commit;

Commit complete.

EODA@PROD1> analyze table t compute statistics;

Table analyzed.

EODA@PROD1> select table_name,num_rows,chain_cnt from user_tables where table_name='T';

TABLE_NAME			 NUM_ROWS  CHAIN_CNT
------------------------------ ---------- ----------
T				     1000	 967

--使用脚本创建CHAINED_ROWS表
EODA@PROD1> @?/rdbms/admin/utlchain

Table created.

EODA@PROD1> desc chained_rows
 Name						       Null?	Type
 ----------------------------------------------------- -------- ------------------------------------
 OWNER_NAME							VARCHAR2(30)
 TABLE_NAME							VARCHAR2(30)
 CLUSTER_NAME							VARCHAR2(30)
 PARTITION_NAME 						VARCHAR2(30)
 SUBPARTITION_NAME						VARCHAR2(30)
 HEAD_ROWID							ROWID
 ANALYZE_TIMESTAMP						DATE

EODA@PROD1> analyze table t list chained rows into chained_rows;  --自动分析并存入CHAINED_ROWS表

Table analyzed.

EODA@PROD1> select count(*) from chained_rows;

  COUNT(*)
----------
       967

--通过重新插入解决行迁移
EODA@PROD1> create table tmp as select * from t where rowid in (select head_rowid from chained_rows);

Table created.

EODA@PROD1> delete t where rowid in (select head_rowid from chained_rows);

967 rows deleted.

EODA@PROD1> insert into t select * from tmp;

967 rows created.

EODA@PROD1> commit;

Commit complete.

EODA@PROD1> analyze table t compute statistics;

Table analyzed.

EODA@PROD1> select table_name,num_rows,chain_cnt from user_tables where table_name='T';

TABLE_NAME			 NUM_ROWS  CHAIN_CNT
------------------------------ ---------- ----------
T				     1000	   0


EODA@PROD1> drop table tmp purge;

Table dropped.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值