简体   繁体   English

删除表中的记录在Oracle中包含1.8亿

[英]Deleting records in table contains 180 Million in oracle

Friends, 朋友们,

I have order tables which have minimum 100 Million records in each table. 我有订单表,每个表中至少有1亿条记录。 We have a job running which invokes a stored procedure which deletes atleast 50K (MIN) and 200K (MAX) records per day. 我们有一个正在运行的作业,它调用一个存储过程,该存储过程每天删除至少50K(MIN)和200K(MAX)记录。

I'm currently using SQL BULK COLLECT to delete records from the table. 我目前正在使用SQL BULK COLLECT从表中删除记录。 Currently it is taking more than 4 hours for deleting 50K which is dead slow. 目前,删除50K耗时超过4个小时,这实在太慢了。

After searching in google, Figured out CTAS method ,i,e Creating table and keeping the records which we want and drop the existing one and rename the temp table. 在google中搜索后,找出CTAS方法,即创建表并保留我们想要的记录,并删除现有记录并重命名temp表。 I CANNOT DO THIS AS THIS OPTION WAS NOT ACCEPTED AS THE TABLES ARE MORE CRITICAL. 我不能执行此操作,因为此表更为重要,因此无法接受此选项。

Could you please suggest some solution to improve the performance of the same? 您能否提出一些解决方案以提高其性能?

Thanks in advance!! 提前致谢!!

Assuming you have enough physical disk space to duplicate your data, you could use the following approach (I assume your table is called ORDERS): 假设您有足够的物理磁盘空间来复制数据,则可以使用以下方法(我假设您的表称为ORDERS):

  • create a copy ORDER_B of your order table with CREATE TABLE orders_b AS SELECT * FROM orders 使用CREATE TABLE orders_b AS SELECT * FROM orders订单表的副本ORDER_B
  • rename your original table to ORDERS_A: ALTER TABLE orders RENAME TO orders_a 将您的原始表重命名为ORDERS_A: ALTER TABLE orders RENAME TO orders_a重命名为ALTER TABLE orders RENAME TO orders_a
  • create a synonym called ORDERS pointing to ORDERS_A: CREATE SYNONYM orders FOR order_a 创建一个名为ORDERS的同义词,该同义词指向ORDERS_A:为order_a CREATE SYNONYM orders FOR order_a

So far, so good. 到现在为止还挺好。 Your client code now uses the synonym ORDERS instead of the physical table. 您的客户端代码现在使用同义词ORDERS而不是物理表。 Now comes the fun part (the daily refresh routine): 现在来了有趣的部分(每日刷新例程):

  • truncate ORDERS_B 截断ORDERS_B
  • fill ORDERS_B with INSERT /*+APPEND+*/ (you might also want to try the PARALLEL hint) INSERT /*+APPEND+*/填充ORDERS_B(您可能还想尝试PARALLEL提示)
  • switch the synonym ORDERS to point to ORDERS_B 切换同义词ORDERS以指向ORDERS_B
  • next day: repeat with ORDERS_A instead of ORDERS_B 第二天:重复ORDERS_A而不是ORDERS_B
  • repeat ad infinitum 无限重复广告

Alternatively, instead of using TRUNCATE/INSERT, you could DROP the table and re-CREATE it. 或者,可以使用删除表并重新创建的方法来代替使用TRUNCATE / INSERT。 This requires more work, since you'll also have to recreate indices and grants. 这需要更多的工作,因为您还必须重新创建索引和授权。

This technique is called synonym switching - you might want to read Tyler Muth's article about synonym switching to get a more complete explanation of it. 这项技术称为同义词切换-您可能需要阅读Tyler Muth的有关同义词切换的文章,以获得更完整的解释。

What is the condition for deleting the records? 删除记录的条件是什么?

Maybe you can create a function based index on this table. 也许您可以在此表上创建基于函数的索引。 Then you may delete the records with a single and simple delete statement. 然后,您可以使用一个简单的delete语句删除记录。 Or think about table partitioning. 或考虑表分区。 If your partition key is smart and covers the delete condition you can drop or purge the old partition within a few seconds. 如果您的分区键很灵巧并且涵盖了删除条件,则可以在几秒钟内删除或清除旧分区。

Btw, with package DBMS_REDEFINITION you can change a "normal" table to a partitized table even without interruption of service. 顺便说一句,与包DBMS_REDEFINITION你可以改变一个“正常”表一表partitized甚至无需中断服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM