问题
Here is my query:
SELECT * FROM [GeoName]
WHERE ((-26.3665122100029-Lat)*(-26.3665122100029-Lat))+((27.5978928658078-Long)*(27.5978928658078-Long)) < 0.005
ORDER BY ((-26.3665122100029-Lat)*(-26.3665122100029-Lat))+((27.5978928658078-Long)*(27.5978928658078-Long))
LIMIT 20
This returns the 20 closest points.
Running this in native sqlite returns a result within 78ms, but from within the .Net sqlite environment it takes nearly 1400ms.
Any suggestions?
I have this query within my ORM structure and using parameterized values. Have also tried it as a native text query.
The code that runs the query (inside my ORM layers):
private static IDataReader CallSqlReader(string SqlStatement, Dictionary<string, object> parameters)
{
ConnectionCheck();
try
{
var cmd = conn.CreateCommand();
cmd.CommandText = SqlStatement;
cmd.CommandType = CommandType.Text;
foreach (var item in parameters)
{
cmd.Parameters.AddWithValue(item.Key, item.Value);
}
return cmd.ExecuteReader();
}
catch { }
return null;
}
回答1:
It is expected that a non-native means of accessing a database will be slower, perhaps much slower, than the native means of accessing same database. But wait to see if someone shows up who has had this problem before and has been able to come up with some kind of solution to it. In the mean time, it will probably help if you show exactly how you execute this query from within dotnet.
来源:https://stackoverflow.com/questions/8777456/sqlite-net-much-slower-than-native