vendredi 6 février 2015

C# SQLite deleting rows really slow

I created a script to delete just about 180 rows in a local sqlite database. Here is my code:



await Task.Run(() =>
{
sql_con.Open();

using (var trans = sql_con.BeginTransaction())
{
foreach (int i in toDelete)
{
cmd = String.Format("DELETE FROM document WHERE docid = '{0}'", i);
sql_cmd = new SQLiteCommand(cmd, sql_con);
sql_cmd.ExecuteNonQuery();
}
trans.Commit();
}

sql_con.Close();
}).ConfigureAwait(false);


I tested it with a stopwatch and Debug.WriteLine...it takes randomly about 2-12 seconds. But it should only take about some milliseconds. The docid column is marked as a index column and in the database are not more than 500 rows or so.


If I use the same script to insert things, it takes just about some milliseconds.


Any ideas?


Aucun commentaire:

Enregistrer un commentaire