因此,我认为问题可能出在System.Data.SQLite上。我在C++中尝试了以下代码:
#include "sqlite3.h"
#include <stdio.h>
void xProfile(void* pArg, const char* query, sqlite3_uint64 pTimeTaken)
{
printf("%s\n", query);
printf("%I64d ms\n", pTimeTaken / 1000000);
}
void PoorPerformance();
void GoodPerformance();
int main()
{
printf("Poor Performance:\n");
PoorPerformance();
printf("Good Performance:\n");
GoodPerformance();
return 0;
}
void PoorPerformance()
{
int rc;
int rowCount = 0;
sqlite3 *db;
if (sqlite3_open("<<File Here>>", &db))
{
printf("Could not open the database.");
return;
}
sqlite3_profile(db, &xProfile, NULL);
sqlite3_stmt *statement;
if (!sqlite3_prepare_v2(db, "SELECT * FROM SearchResults WHERE ContactName LIKE @ContactName;", -1, &statement, 0))
{
int result = 0;
int parameterIndex = sqlite3_bind_parameter_index(statement, "@ContactName");
sqlite3_bind_text(statement, 1, "test", -1, NULL);
while (result != SQLITE_DONE)
{
result = sqlite3_step(statement);
if (result == SQLITE_ROW)
{
rowCount++;
}
}
sqlite3_finalize(statement);
}
printf("%d rows\n", rowCount);
sqlite3_close(db);
}
void GoodPerformance()
{
int rc;
int rowCount = 0;
sqlite3 *db;
if (sqlite3_open("<<File Here>>", &db))
{
printf("Could not open the database.");
return;
}
sqlite3_profile(db, &xProfile, NULL);
sqlite3_stmt *statement;
if (!sqlite3_prepare_v2(db, "SELECT * FROM SearchResults WHERE ContactName LIKE 'test';", -1, &statement, 0))
{
int result = 0;
while (result != SQLITE_DONE)
{
result = sqlite3_step(statement);
if (result == SQLITE_ROW)
{
rowCount++;
}
}
sqlite3_finalize(statement);
}
printf("%d rows\n", rowCount);
sqlite3_close(db);
}
无论是PoorPerformance函数还是GoodPerformance函数,都得出了11行1毫秒的结果。我所做的和System.Data.SQLite应该做的有什么不同吗?希望这只是需要报告给System.Data.SQLite的一个bug,并可能采用自己的修复。
SqlQuery
方法的源代码吗?你确定你正在计时的是查询本身,还是包括创建参数并将其添加到集合的开销?(这几乎没有开销,但在查看方法的源代码之前我们无法确定) - vcsjonesentities
项的构建。我将修改帖子以包含所有必要的部分。 - Terry