【问题标题】:Oracle 20 million update based on joinOracle 2000万更新基于join
【发布时间】:2016-05-12 05:10:32
【问题描述】:

我需要做以下事情

  UPDATE TABLE2 t2
SET t2.product_id = (select t1.product_id from
table1 t1 where t1.matching_id = t2.matching_id)

除了 TABLE2 有 2700 万条记录。 product_id 是一个新添加的列,因此向其填充数据。 我可以使用游标,将 TABLE2 中的记录集分解为相当小的数字,但是有 2700 万条记录,我不确定最好的方法是什么。 请建议,即使这意味着将我的数据导出到 Excel。

更新 - 匹配的列也被编入索引。

【问题讨论】:

  • 我认为这是正确的方法,只要您有一个正确的 matching_id 索引。你试过了吗?有什么错误吗?
  • 300 万条记录,耗时 30 分钟。我没有尝试2700万。如果需要 30*9 分钟不可行:)
  • 你有matching_id的索引吗?在两张桌子上
  • table1 的大小是多少?
  • 如果时间不是一个约束,将其包装到 DBMS_JOB 或 DBMS_SCHEDULER(参见CREATE_JOB)并让它运行。

标签: oracle performance plsql oracle11g


【解决方案1】:

我唯一能做的就是替换 CREATE TABLE AS 的更新

  CREATE TABLE table2_new AS
        SELECT t2.* (less product_id), t1.product_id
        FROM table1 t1
        JOIN table2 t2
          ON t1.matching_id = t2.matching_id

但稍后您将不得不手动添加CONSTRAINTS,删除table2 并替换为table2_new

【讨论】:

  • 我可以试试这个,但是有很多删除和重新创建约束、索引、默认值等,
  • CTAS (Create table .. as select) 可能是正确的答案。如果您有足够的 CPU 和 IO 资源,您也可以使用一些并行性。
【解决方案2】:
update (select t1.product_id as old_product_id, t2.product_id as new_product_id
        from table1 t1
        join table2 t2 on (t1.matching_id = t2.matching_id)) t
set t.new_product_id = t.old_product_id

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-21
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 1970-01-01
    • 2021-02-04
    • 2011-12-19
    • 1970-01-01
    相关资源
    最近更新 更多