首页 > 解决方案 > 为什么我的 sqlalchemy/sqlite 更新这么慢?

问题描述

我在 sqlite 数据库上使用 sqlalchemy。如果我执行一堆 select 语句,它比在相同条目上执行一堆更新快 10 倍以上。

这样做 1000 次需要 5.12 秒:

update_stmnt = sqlalchemy.update(table).where(table.c.id==my_id).values(para_type=my_label, score=my_score)
conn.execute(update_stmnt)

而这样做 1000 次只需要 428 毫秒:

select_st = sqlalchemy.select([table]).where(table.c.id == my_id)
res = conn.execute(select_st)

为什么 select 语句可能比更新快得多?有什么方法可以构建我的更新语句以使其更快?

标签: sqlitesqlalchemy

解决方案


推荐阅读