【发布时间】:2013-06-29 20:24:12
【问题描述】:
我尝试使用“Python 2.7.4 + sqlite3”和“Firefox SQLite Manager 0.8.0”处理对同一数据库的相同请求。
在小型数据库(8000 条记录)上,Python 和 Firefox 运行速度很快,并给出相同的结果。
在更大的数据库上(2600000 条记录):
- SQLite 管理器在 28 秒内处理数据库(24 条记录)
- Python 程序已经运行了 20 分钟,没有任何结果
下面的程序有什么问题,导致python sqlite3无法在合理的时间内处理查询,而相同的请求可以更快地处理?
import sqlite3
_sql1 = """SELECT DISTINCT J2.rule_description,
J2.feature_type,
J2.action_item_id,
J2.rule_items
FROM journal J1,
journal J2
WHERE J1.base = J2.base
AND J1.action_item_id=J2.action_item_id
AND J1.type="Action disabled"
AND J2.type="Action applied"
AND J1.rule_description="Some test rule"
AND J1.action_item_id IN (1, 2, 3, 14, 15, 16, 17, 18, 19, 30, 31, 32)
"""
if __name__ == '__main__':
sqlite_output = r'D:\results.sqlite'
with sqlite3.connect(sqlite_output) as connection:
for row in connection.execute(_sql1):
print row
更新:Command Line Shell For SQLite 也返回相同的 24 条记录
UPDATE2: sqlite3.sqlite_version 是 '3.6.21'
【问题讨论】:
-
您确定 SQLite 管理器正在处理 所有 结果行吗?你的 Python 程序是……
-
是的,“SQLite 的命令行外壳”也给出了相同的 24 条记录
-
可能是数据库文件被SQLite Manager锁定了?
-
检查 SQLite 版本 (
SELECT sqlite_version();)。 -
数据库未锁定:重启后一样
标签: performance python-2.7 python-3.x sqlite