Python sqlite3需要很长时间才能使用ORDER BY查询INNER JOIN

时间:2016-10-27 17:48:26

标签: python python-2.7 sqlite

我正在使用带有sqlite3模块的Python 2.7。

这是查询:

SELECT l.bggid, l.name FROM lastmonth l 
INNER JOIN firstmonth f ON f.bggid = l.bggid
ORDER BY l.bggid DESC 
LIMIT 20;

此查询适用于独立的SQLite,但Python卡住了,需要将近10分钟才能执行相同的查询。

然而,如果我注释掉ORDER BY行或INNER JOIN行,或者如果我加入其他能力,它在Python中工作正常。

完整的脚本如下:

import sqlite3


# Connect to SQLite Database
db_loc = 'boardgamecollection_xml.sqlite' # name of database
conn = sqlite3.connect(db_loc)
c = conn.cursor()

query = '''SELECT l.bggid, l.name FROM lastmonth l 
INNER JOIN firstmonth f ON f.bggid = l.bggid
ORDER BY l.bggid DESC 
LIMIT 20;'''

c.execute(query)
print 'here'
print c.fetchall()
print "done"

conn.close()

编辑: 我从sqlite3模块切换到apsw,这似乎解决了这个问题。

0 个答案:

没有答案