如何让循环中的多条数据库查询语句执行的更快
有一个200次循环里面放了四个SQL语句,速度要10秒才执行完。速度太慢了各位大侠有什么好办法吗?
以下代码每去掉一个SQL的操作,其它代码不动速度就会快2秒。
希望各位能给小弟指导,弄了几天了速度还是达不到要求。
ADO已设置为CacheSize=1000 CursorLocation = clUseClient CursorType= ctStatic LockType= itOptimistic Prepared = true
for(int i=0;i<200;i++) { //Application->ProcessMessages(); //DataModule1->ADOQuery1->Close(); DataModule1->ADOQuery1->SQL->Clear(); DataModule1->ADOQuery1->SQL->Add("select Te from a where at="+IntToStr(i+1)); DataModule1->ADOQuery1->Open(); //相关处理略。。。。 //DataModule1->ADOQuery1->Close(); DataModule1->ADOQuery1->SQL->Clear(); DataModule1->ADOQuery1->SQL->Add("select Te from b where bt="+IntToStr(i+1)); DataModule1->ADOQuery1->Open(); //相关处理略。。。。 //DataModule1->ADOQuery1->Close(); DataModule1->ADOQuery1->SQL->Clear(); DataModule1->ADOQuery1->SQL->Add("select Te from c where ct="+IntToStr(i+1)); DataModule1->ADOQuery1->Open(); //相关处理略。。。。 //DataModule1->ADOQuery1->Close(); DataModule1->ADOQuery1->SQL->Clear(); DataModule1->ADOQuery1->SQL->Add("select Te from d where dt="+IntToStr(i+1)); DataModule1->ADOQuery1->Open(); } }
//DataModule1->ADOQuery1->Close();
DataModule1->ADOQuery1->SQL->Clear();
DataModule1->ADOQuery1->SQL->Add("select Te, at from a");
DataModule1->ADOQuery1->Open();
//DataModule1->ADOQuery2->Close();
DataModule1->ADOQuery2->SQL->Clear();
DataModule1->ADOQuery2->SQL->Add("select Te, bt from b");
DataModule1->ADOQuery2->Open();
//DataModule1->ADOQuery3->Close();
DataModule1->ADOQuery3->SQL->Clear();
DataModule1->ADOQuery3->SQL->Add("select Te, ct from c");
DataModule1->ADOQuery3->Open();
//DataModule1->ADOQuery4->Close();
DataModule1->ADOQuery4->SQL->Clear();
DataModule1->ADOQuery4->SQL->Add("select Te, dt from d");
DataModule1->ADOQuery4->Open();
AnsiString Filter;
for(int i=0;i <200;i++)
{
//Application->ProcessMessages();
Filter = IntToStr(i+1);
DataModule1->ADOQuery1->Filtered = false;
DataModule1->ADOQuery1->Filter = "at = "+Filter;
DataModule1->ADOQuery1->Filtered = true;
//相关处理略。。。。
DataModule1->ADOQuery2->Filtered = false;
DataModule1->ADOQuery2->Filter = "bt = "+Filter;
DataModule1->ADOQuery2->Filtered = true;
//相关处理略。。。。
DataModule1->ADOQuery3->Filtered = false;
DataModule1->ADOQuery3->Filter = "ct = "+Filter;
DataModule1->ADOQuery3->Filtered = true;
//相关处理略。。。。
DataModule1->ADOQuery4->Filtered = false;
DataModule1->ADOQuery4->Filter = "dt = "+Filter;
DataModule1->ADOQuery4->Filtered = true;
//相关处理略。。。。
}