【发布时间】:2014-06-19 10:43:46
【问题描述】:
我有一个 SQLite 数据库(第一个使用 SQLite 的项目),我需要一次删除大量记录,这就像 14.000 条记录。问题如下(我更改了名称以便更好地阅读):
delete from table_1 where table_2_id in (
select id from table_2 where table_3_id in (
select id from table_3
where (deleted = 1 or
table_4_id in (select id from table_4 where deleted = 1))));
删除此查询大约需要 8 分钟。但是当我这样做时
select * from table_1 where table_2_id in (
select id from table_2 where table_3_id in (
select id from table_3
where (deleted = 1 or
table_4_id in (select id from table_4 where deleted = 1))));
它会在 3 秒内给我一个结果。
我尝试使用事务、缓存大小、日志模式,但我没有让它工作以获得更好的性能。我错过了什么?
【问题讨论】:
-
创建临时表(
CREATE TEMP TABLE to_delete AS select table_1_id FROM table1 ...);使用它删除的速度有多快 (delete from table_1 where table_1_id in to_delete)? -
感谢您的快速回复。创建临时表需要不到一秒钟的时间,所以看起来性能是正确的。要使用查询“从 table_1 中删除 table_1_id in (select id from to_delete)”删除特定数据,它又需要大约 8 分钟。
-
数据库文件有多大?你有多少内存?什么文件系统?网络?
-
目前我有以下规格:大小 = 30MB,内存:8GB,磁盘:SSD,系统:Windows 7,网络:本地存储
-
30 MB?不是国标?你有病毒扫描程序吗?
标签: performance sqlite sql-delete