python - 性能调整:使用集合或数据框比较两个表:获取最终消息为“Killed”
问题描述
我的表很少,表将在不同的数据库中,下面是我正在尝试的示例比较
EmplTbl = cur.execute("select A , B , C from EmployeeTable where EmplName in ('A','B')")
emp_entries = set(cur)
DeptTbl = cur.execute("select A , B , C from DeptTable")
dept_entries = set(cur)
print(emp_entries.difference(dept_entries))
在这个例子中,我只提供了 3 列进行比较。但就我而言,我有 30-40 列。当我尝试在集合之间进行区分或使用“for”循环或数据帧连接比较时——脚本运行速度非常慢,我收到的最终消息是“已杀死”
在下面的代码中,我尝试进行内部连接以获得完全匹配
EmplTbl = cur.execute("select A , B , C from EmployeeTable where EmplName in ('A','B')")
emp_entries = set(cur)
DeptTbl = cur.execute("select A , B , C from DeptTable")
for DeptTbl in cur:
if emp_entries in DeptTbl:
print(emp_entries)
记录量:我可能有多达 1000 万条记录
有什么办法可以提高我的性能使它运行得更快。我有 4 个节点配置的 linux 服务器。请建议
解决方案
您可以直接使用查询差异:
Select col1, col2, col3 from table 1
Minus
Select col1, col2, col3 from table2;
- 或者 -
Select col1, col2, col3 from table1 t1
Where exists
(Select 1 from table2 t2
Where t1.col1 = t2.col1
And t1.col2 = t2.col2
And t1.col3 = t2.col3)
干杯!!
推荐阅读
- javascript - 控制 v-for 项目的定位
- design-patterns - 如何在颤振/飞镖中绘制弹出布局?
- c - 如何从 typedef 创建一个静态结构
- python - 从python的字符串中提取数值
- function - 在函数中使用子字符串方法会破坏其他字符串
- kubernetes - 如何在 kubernetes 上启动 kafka
- powershell - 有没有办法通过〜过滤文件名?
- apache-spark - 使用 Apache Spark 和 OpenCV 进行图像分析
- git - 如何为 CI 组织两个 git repos
- sql - 合并 ContainerID 行并添加 Qty