使用ADO的Next函数对数据集遍历越来越慢
c1aud 2008-03-28 05:23:22 使用的数据库是Microsoft SQL Server 2000
使用编译器是C++ Builder 6
我有如下一段代码
#include <mmsystem.h>
TADOQuery* ADOQuery1;
.....
DWORD startTime = ::timeGetTime();
ADOQuery1->Close();
ADOQuery1->SQL->Text = "select [MsgId],[MsgText] from MsgInfo";
ADOQuery1->Open();
DWORD time2 = (::timeGetTime()-startTime)/1000;
AnsiString strLog;
strLog.sprintf("Loaded MsgInfo from Database, count: %d, time cost: %d", ADOQuery1->RecordCount, time2);
PrintLog(str1);
int t = 0;
ADOQuery1->First();
startTime = ::timeGetTime();
while( !ADOQuery1->Eof )
{
t++;
if( !(t%5000) )
{
time2 = (::timeGetTime()-startTime)/1000;
strLog.sprintf("Loading MsgInfo from Recordset, time cost: %d", time2);
PrintLog(str2);
}
ADOQuery1->Next();
}
time2 = (::timeGetTime()-startTime)/1000;
strLog.sprintf("Loaded MsgInfo from Recordset, time cost: %d", time2);
PrintLog(str2);
执行后获得如下日志
Loaded MsgInfo from Database, count: 41503, time cost: 1
Loading MsgInfo from Recordset, time cost: 1
Loading MsgInfo from Recordset, time cost: 3
Loading MsgInfo from Recordset, time cost: 5
Loading MsgInfo from Recordset, time cost: 8
Loading MsgInfo from Recordset, time cost: 12
Loading MsgInfo from Recordset, time cost: 17
Loading MsgInfo from Recordset, time cost: 22
Loading MsgInfo from Recordset, time cost: 28
Loading MsgInfo from Recordset, time cost: 34
Loading MsgInfo from Recordset, time cost: 42
Loaded MsgInfo from Recordset, time cost: 45
为什么Next访问速度会越来越慢?
我查了CSDN之前有个类似的问题,但是没有找到答案,请大侠帮忙看看。
http://topic.csdn.net/t/20031114/17/2461467.html