ORACLE ROW MOVEMENT

发布时间:2020-08-18 13:34:05 作者:Davis_itpub
来源:ITPUB博客 阅读:139
<div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <span style="background-color:inherit;line-height:1.5;">ROW MOVEMENT特性最初是在8i时引入的,其目的是提高分区表的灵活性,这一特性默认是关闭,只要使用一下3个功能才需要打开:&nbsp;</span> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <b style="background-color:inherit;">1.Flashback Table </b> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 这一功能能帮助我们及时回滚一些误操作,防止数据意外丢失。在使用该功能之前,必须先打开ROW MOVEMENT,否则就会抛ORA-08189错误。 </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> select username, rowid from test_move; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> delete from test_move where username = 'MYTBC'; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> commit; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> alter table test_move enable row movement; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> flashback table test_move to timestamp(systimestamp - interval '3' minute); </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> --闪回到3分钟前得状态,那时username='MYTBC'记录未被删除。 </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> select username, rowid from test_move; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> --查询可知,数据被找回来,此时,再比较flashback前后记录的ROWID,大多数记录的物理位置都变化。 </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 这个过程的内部操作, 可以通过对Flashback Table做SQL Trace来进一步观察。通过Trace,我们不难发现, </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> Flashback Table实际是通过Flashback Query将表中数据进行了一次删除、插入操作,因此ROWID会发生变化。 </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <b style="background-color:inherit;">2.Shrink Segment (减低表的高水位) </b> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> Shrink Segment能帮助我们压缩数据段、整理数据碎片、降低高水位,以提高性能、节省空间。它也同样要求开启ROW MOVEMENT。 </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> select username, rowid from test_move; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> delete from test_move where username = 'MYTBC'; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> --这个时候 shrink space 会报10636错误 </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> alter table test_move enable row movement; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> alter table test_move shrink space; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> select username, rowid from test_move; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 我们可以看到在Shrink后,ROWID也变化了。从对其过程的Trace来看,Shrink对数据的改变不是通过SQL实现的,而是通过更底层的函数来实现的。 </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <b style="background-color:inherit;">3.更新Partition Key </b> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 在更新记录中的Partition Key时,可能会导致该记录超出当前所在分区的范围,需要将其转移到其他对应分区上,因此要求开启ROW MOVEMENT。 </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> drop table test_move; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> create table test_move </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> partition by list (owner) </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> (partition p1 values ('SYS'), </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> partition p2 values ('DEMO'), </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> partition p3 values ('SYSTEM'), </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> partition def values (default)) </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> as select * from dba_tables; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> --这个时候update会报14402错误 </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> alter table test_move enable row movement; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> update test_move set owner='SYS' where owner='DEMO' and table_name='T_TEST'; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 这一操作产生影响的特殊之处在于这是个DML操作,是和online transaction密切相关。对于这样一个UPDATE,实际上分为3步:先从原有分区将数据删除;将原数据转移到新分区上;更新数据。 </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 其影响就在于以下几个方面: </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 一个UPDATE被分解为DELET、INSERT、UPDATE三个操作,增加了性能负担。其中,DELETE的查询条件与原UPDATE的查询条件相同,新的UPDATE的查询条件是基于INSERT生成的新的ROWID; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 相应的Redo Log、Undo Log会增加; </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 如果Update语句还涉及到了Local Index的字段的话,新、旧2个分区上的Local Index都要被更新。 </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> <br style="background-color:inherit;" /> </div> <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;background-color:#FFFFFF;"> 还有一点,Row Movement会和域索引(Domain Index)产生冲突:如果表上定义了域索引,开启Row Movement就会失败;反之亦然。 </div>
推荐阅读:
  1. oracle 表收缩
  2. oracle备份与恢复--闪回技术

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

movement oracle row

上一篇:人脸识别最终章--人脸识别

下一篇:深度解析:主流分布式架构的前世今生

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》