sqlite - 为什么我的 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 语句可能比更新快得多?有什么方法可以构建我的更新语句以使其更快?
解决方案
推荐阅读
- audio - 使用 pydub 更改 BPM
- javascript - 如何通过 cdn 脚本注册 service worker。如何使用外部 url 注册 service worker
- python - 函数不能接受元组输入?
- kubernetes - Kubernetes 在 values.yaml 中使用 {{ include xx }}
- reactjs - 复制到剪贴板特定项目
- assembly - 使用立即操作数编码 x86-16 指令
- google-kubernetes-engine - 入口规则不会在 Pod 之间平均分配流量,
- c++ - 检查向量的重复频率
- asp.net-mvc - ASP .NET MVC 无法将图像上传到 Blob 存储
- forms - IF 条件不适用于 Microsoft PowerApps 中的两个下拉菜单