我有一个包含50亿行(table1)的表,另一个表在表2中有30亿行。这两个表是相关的。我必须从表1中删除30亿行及其来自表2的相关行。表1是表2的子项。我尝试使用plsql中的for all方法,它没有多大帮助。然后我想到了使用oracle分区策略。由于我不是DBA,我想知道是否可以在选定数量的id的主键列上分配现有表格?我的主键是64位自动生成的数字。
答案 0 :(得分:3)
在线分割对象很困难(可以使用dbms_redefinition完成)。而且没有必要(有你提供的细节)。
最好的想法是重新创建没有不需要的行的对象。
例如,一些简单的代码就像:
create table undesired_data as (select undesired rows from table1);
Create table1_new as (select * from table1 where key not in (select key from undesired_data));
Create table2_new as (select * from table2 where key not in (select key from undesired_data));
rename table1 to table1_old;
rename table2 to table2_old;
rename table1_new to table1;
rename table2_new to table2;
recreate constraints;
check if everything is ok;
drop table1_old and table2_old;
这可以离线消费者,但如果脚本没问题,他们的停机时间会非常短(你应该在测试环境中对它们进行测试)。
答案 1 :(得分:0)
听起来非常可疑
如果它是真实用例,那么您不能删除您创建另一个表格,包括已分区的表格,并使用insert /*+ append */ into MyNewTable select ...
填写它。
最常见的做法是在日期定义分区(记录创建日期,事件日期等)
再说一次,如果这是一个真实的用例,我强烈建议您寻求真正的帮助,而不是在互联网上寻求建议而不是自己做。