python - MySQL - 匹配两个包含巨大数据的表并找到相似的数据

标签 python mysql sql

我的 SQL 中有两个表。 表1数据较多,表2数据量较大。

这是我使用 Python 实现的代码

import MySQLdb

db = MySQLdb.connect(host = "localhost", user = "root", passwd="", db="fak")
cursor = db.cursor()

#Execute SQL Statement:
cursor.execute("SELECT invention_title FROM auip_wipo_sample WHERE invention_title IN (SELECT invention_title FROM us_pat_2005_to_2012)")

#Get the result set as a tuple:
result = cursor.fetchall()

#Iterate through results and print:
for record in result:
    print record
print "Finish."

#Finish dealing with the database and close it
db.commit()
db.close()

但是,这需要很长时间。我已经运行了 Python 脚本 1 小时,但它仍然没有给我任何结果。

请帮助我。

最佳答案

两个表中都有 Invention_title 索引吗?如果没有,则创建它:

ALTER TABLE auip_wipo_sample ADD KEY (`invention_title`);
ALTER TABLE us_pat_2005_to_2012 ADD KEY (`invention_title`);

然后将您的查询合并为一个不使用子查询的查询:

SELECT invention_title FROM auip_wipo_sample 
INNER JOIN us_pat_2005_to_2012 ON auip_wipo_sample.invention_title = us_pat_2005_to_2012.invention_title

让我知道你的结果。

关于python - MySQL - 匹配两个包含巨大数据的表并找到相似的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16632582/

相关文章:

sql - 地址解析 - 楼层#

python - 在多个图形上绘制一条线

python - 使用sdl2绘制轮廓圆

python - 使用 ctypes 时 undefined symbol

mysql - 为什么我得到 "error code 1005 can t create c errno 150 mysql "?

php - 使用我刚刚添加的索引列的数据

mysql - MySql中根据两列删除重复记录

sql - 将两个表与一个表中的两个结果连接起来

MATLAB vec2mat 的 Python 等效代码

sql - 是否可以创建从 "horizontal"到 "vertical"的 sql View