我有SQLite database (.db)
性能问题与SQLite数据库(.db的)
我试图更新1,00,000记录数据库(.db的),它以大约50分钟车性能问题。太慢了。
我的代码是像下面::
for (int q = 0; q < list.Count; q++)
{
ArrayList castarraylist = new ArrayList();
castarraylist = (ArrayList)(list[q]);
using (var cmd = new SQLiteCommand(con))
using (var transaction = con.BeginTransaction())
{
cmd.Transaction = transaction;
for (int y = 0; y < castarraylist.Count; y++)
{
cmd.CommandText = Convert.ToString(castarraylist[y]);
cmd.ExecuteNonQuery();
}
transaction.Commit();
GC.Collect();
}
}
这里每个castarraylist包含5000条记录。用事务更新到数据库中。所以循环经过20次并完成全部更新。 虽然我手动检查时间增加了5000次记录每次迭代的时间。像
1st 5000 records processing time > 1:11 minute
2nd 5000 records processing time > 1:25 minute
3rd 5000 records processing time > 1:32 minute
4th 5000 records processing time > 1:40 minute
5th 5000 records processing time > 1:47 minute
6th 5000 records processing time > 1:52 minute
...
...
...
17th 5000 records processing time > 3:32 minute
18th 5000 records processing time > 3:44 minute
19th 5000 records processing time > 4:02 minute
20th 5000 records processing time> 4:56 minute
为什么发生这种情况我无法理解。 我的源代码写在C#和我的笔记本电脑的配置是i5 2.6 GHz
,4 GB RAM
,500 GB HD
。
我喜欢做下面联系::
SQLiteConnection con = new SQLiteConnection("Data Source=" + fullPath + ";Version=3;Count Changes=off;Journal Mode=off;Pooling=true;Cache Size=10000;Page Size=4096;Synchronous=off");
(* FULLPATH - 是我的数据库路径)
我创建的表像下面...
sqlquery2="Select LINK_ID from RDF_LINK
string createLinkToPoly = "create table temp2 AS " + sqlquery2;
这将创建一个表并插入sqlquery2获取的记录。
以下语句扩展Spatialite上的SQLite
ExecuteStatement("select load_extension('spatialite.dll')", con);
我Update
语句像下面::
UPDATE temp2 SET GEOM = Transform(LineStringFromText('LINESTRING(4.38368 51.18109,4.38427 51.18165)',4326),32632)WHERE LINK_ID= 53841546
所以这种说法100000建筑物在不同的线程,并插入到LIST
在上面的代码中最后执行UPDATE
语句(现在用拉里的代码提示)
什么实际执行的SQL命令? –
为什么GC.Collect()? – Larry
@CL。实际的命令是在** castarraylist ** – Hardik