sql - oracle 中的合并命令导致空间不足问题
问题描述
我在 oracle db 中有 300 万条记录的 table1。我需要使用 table2 和 table3 中的数据更新 table1 中大约 200 万条记录的一列。
我对这 3 个表的数据模型是
table1 has id, DOI
table2 has product_code, id
table3 has DOI and productcode
我正在使用合并命令,因为在这种情况下更新命令非常耗时。
merge into table1
using
(select p.id, stg.doi from table2 p, table3 stg, table1 pc where stg.productcode = p.product_code and pc.product_id = p.id) st
on (st.id = table1.product_id)
when matched then update set table1.doi = st.doi;
commit;
由于所有这 3 个表都有数百万条记录,临时表总是空间不足导致合并脚本突然停止。DBA 已分配 64gb 的空间,但我们的临时空间仍然不足。
有什么建议么?
解决方案
您可以添加WHERE
子句:
merge into product_content
using (select p.id, stg.doi
from table2 p
JOIN table3 stg ON stg.productcode = p.product_code
JOIN table1 pc ON pc.product_id = p.id) st
-- modern explicit JOIN
on (st.id = product_content.product_id)
when matched then update set product_content.doi = st.doi
where product_content.doi != st.doi;
-- assuming that doi is defined as NOT NULL
-- there is no need for update if nothing has changed
推荐阅读
- xpath - XPath:查找祖先元素中的下一次出现
- python - 达到第一个 TRUE 条件后停止条件循环
- c# - BoolToVisibilityConverter 未在 UWP 中触发
- forms - 关闭另一个表单时重新查询辅助表单上的列表框
- python - 如何找到连续减少(增加)的数量
- c - 在文件名中添加数字
- git - 不适用于 docker executor 的 gitlab-runner queue
- angular - 占位符输入文本未以角度显示
- r - 有没有办法将 CSS 样式添加到 flextable(用于在 RStudio/浏览器中以 html 格式呈现)?
- amazon-web-services - 如何忽略亚马逊雅典娜结构顺序