python-3.x - cx_Oracle 中批量处理的性能改进
问题描述
使用 cx_Oracle 将数据批量加载到 oracle 时面临性能问题。似乎附加提示不适用于 cx_Oracle 或至少我无法使其工作。任何帮助将不胜感激
我试图使用 cx_Oracle 将 200 万条记录批量推送到 Oracle,但是如果我使用附加提示,它只需要 20 秒,而从 oracle 到 oracle 需要 1.5 分钟。
insertquery="""insert /*+ append parallel(XYZ,8) */ into XYZ(A,B,C,D,E,F,G,H, I,J,K,L,M,N,O,P,Q,R,S) VALUES('abc',:B,'N',:D,:E,:F,:G,:H,:I,:J,:K,:L,:M,:N,:O,'MIG','MIG',{current_time},{current_time})""".format(current_time=current_time)
print("XYZ START",datetime.datetime.now())
trg_cur.prepare(insertquery)
trg_cur.executemany(None,entityList)'''
如果我保留附加提示,所用时间保持不变。除了线程之外,还有什么方法可以提高这种性能,我会在多个线程中运行它,因为我的输入数据范围可以达到几亿行,我必须将此数据插入多个表中
解决方案
using append_Values worked like a charm and 40 sec reduced to 10 sec for pushing 1 million records
insertquery="""insert /*+ append_values parallel(XYZ,8) */ into XYZ(A,B,C,D,E,F,G,H, I,J,K,L,M,N,O,P,Q,R,S) VALUES('abc',:B,'N',:D,:E,:F,:G,:H,:I,:J,:K,:L,:M,:N,:O,'MIG','MIG',{current_time},{current_time})""".format(current_time=current_time)
推荐阅读
- material-ui - 材质 UI 选项卡没有选择的选项卡
- drools - 无法使用在 kie-wb-7.5.0 上具有开发人员角色的用户覆盖以前构建的项目。(drools)
- c# - 如何在应用程序仍在运行时阻止控制台返回附加到控制台的 WPF 应用程序
- java - JavaFX TextField 覆盖键 UP/DOWN 行为
- c++ - 具有随机密钥生成的双重 AES 加密
- flutter - Flutter Overlay 和 TextFields
- asp.net-mvc - 删除具有外键关系的实体而不删除引用对象
- java - 尝试为对象分配随机 ID
- html - 打开软件键盘时保持页脚可见
- android - 具有多个主题的firebase消息传递条件不起作用