python - MySQL SSDictCursor fetchone() 花费太多时间
问题描述
我正在处理大量数据,我正在优化我的处理循环,但仍然需要太多时间。所以我注意到我的数据集中每 1000-2000 行都使用 fetchone() 获取 1-5 秒!而所有其他人需要 10-30 纳秒(!)秒
db = MySQLdb.connect(host="localhost", user="****", passwd="****", db="****", charset='utf8',
cursorclass=MySQLdb.cursors.SSDictCursor)
c = db.cursor()
c.execute(sql)
while True:
event = c.fetchone()
if not event:
return
print(event)
我正在打印最长的 fetchone() 函数调用:
(row index : time in sec)
1898 : 5.86757670
3783 : 6.63812080
5667 : 5.00934410
7559 : 5.21368210
9425 : 5.49990800
11312 : 4.47716010
但在较小的数据集上,峰值也较小,但它们发生的频率更高:
(row index : time in sec)
561 : 0.00169070
714 : 1.43662880
1416 : 2.07252320
2106 : 1.77626870
2811 : 1.78253030
PS我想这可能是范围优化的问题,因为我里面有一个很大的“id in ( ID's LIST )”表达式。但我对 NO_RANGE_OPTIMIZATION 提示有疑问。
解决方案
推荐阅读
- r - 如何在函数中使用“sqldf”
- ubuntu - 为什么 g++ 无法在 Ubuntu 中正确找到 glfw3 库?
- python - 将数据框转换为rec数组(将对象转换为字符串)
- android - com.google.gson.stream.MalformedJsonException:第 1 行第 1 列 1273834 路径处的未终止字符串
- glidejs - 如何访问“build.after”中的组件大小 [Glide.js v 3.1.0]
- c# - Azure B2C 使用 Graph API 登录
- arrays - 将包含两个特定字符串的文件列表到bash中的数组中
- linux - 具有可选多平台驱动程序接口的 Linux 设备驱动程序
- javascript - 如何更改javascript构造函数中的现有参数
- mysql - 孤立表崩溃 MySql