好吧,我有一个file.sql
包含20,000
插入命令的
.sql
来自文件的样本
插入
table
值(1,-400,400,3,154850,'Text',590628,'TEXT',1610,'TEXT',79);插入
table
值(39,-362,400,3,111659,'Text',74896,'TEXT',0,'TEXT',14);
我正在使用以下代码创建内存中的 Sqlite 数据库并将值拉入其中然后计算经过的时间
using (var conn = new SQLiteConnection(@"Data Source=:memory:"))
{
conn.Open();
var stopwatch = new Stopwatch();
stopwatch.Start();
using (var cmd = new SQLiteCommand(conn))
{
using (var transaction = conn.BeginTransaction())
{
cmd.CommandText = File.ReadAllText(@"file.sql");
cmd.ExecuteNonQuery();
transaction.Commit();
}
}
var timeelapsed = stopwatch.Elapsed.TotalSeconds <= 60
? stopwatch.Elapsed.TotalSeconds + " seconds"
: Math.Round(stopwatch.Elapsed.TotalSeconds/60) + " minutes";
MessageBox.Show(string.Format("Time elapsed {0}", timeelapsed));
conn.Close();
}
我尝试过的事情
- 使用文件数据库而不是内存之一。
- 使用开始事务和提交事务 [如我的代码中所示]。
- Using Firefox's extension named
SQLite Manager
to test whether the slowing down problem is from the script; However, I was surprised that the same20,000
lines that i am trying to process using my code has been pulled to the database in JUST 4ms!!!. - Using
PRAGMA synchronous = OFF
, as well as,PRAGMA journal_mode = MEMORY
. - Appending
begin transaction;
andcommit transaction;
to the beginning and ending of the.sql
file respectively.
As the SQLite documentations says : SQLite is capable of processing 50,000
commands per seconds. And that is real and i made sure of it using the SQLite Manager
[AS DESCRIPED IN THE THIRD SOMETHING THAT I'V TRIED]; However, I am getting my 20,000
commands done in 4 minutes something that tells that there is something wrong.
QUESTION : What is the problem am i facing why is the Execution done very slowly ?!