我正在使用Perl DBI从MS Access数据库中选择和处理数据。代码运行良好但速度非常慢。从我的数据库中选择只有大约150条记录的数据需要3-4分钟。 我只是在循环之外准备语句。使用fetchrow_array,fetchrow_arrayref,fetchall_arrayref方法,但性能没有太大差别。如何提高执行速度?
my $dbh = DBI->connect('dbi:ODBC:driver=Microsoft Access Driver (*.mdb, *.accdb);dbq=D:\Project\Project\BSC_KPIMonitoring\CHN\E_BSC_KPIMonitorDB.mdb');
my $stat1="SELECT * FROM SDCCHBLOCKING WHERE NE=?";
my $sth1 = $dbh->prepare($stat1);
my $stat2="SELECT * FROM SDCCHDROP WHERE NE=?";
my $sth2 = $dbh->prepare($stat2);
my $stat3="SELECT * FROM TCHBLOCKING WHERE NE=?";
my $sth3 = $dbh->prepare($stat3);
my $stat4="SELECT * FROM TCHDROP WHERE NE=?";
my $sth4 = $dbh->prepare($stat4);
my $sqlstatement="SELECT * FROM KPI_Master";
my $sth = $dbh->prepare($sqlstatement);
$sth->execute ||
die "Could not execute SQL statement ... maybe invalid?";
while (my @row=$sth->fetchrow_array()){
$bsc = $row[0];
$kpi = $row[1];
$thresh= $row[2];
if($kpi eq "SDCCHBLOCKING")
{
$sth1->execute($bsc) ||
die "Could not execute SQL statement ... maybe invalid?";
while (my @row1=$sth1->fetchrow_array())
{
if($row1[2]>$thresh)
{
print "SB,$bsc,$thresh,/$row1[2]";
}
}
}
if($kpi eq "SDCCHDROP")
{
$sth2->execute($bsc) ||
die "Could not execute SQL statement ... maybe invalid?";
while (my @row2=$sth2->fetchrow_array())
{
if($row2[2]>$thresh)
{
print "SD,$bsc,$thresh,/$row2[2]";
}
}
}
if($kpi eq "TCHBLOCKING")
{
$sth3->execute($bsc) ||
die "Could not execute SQL statement ... maybe invalid?";
while (my @row3=$sth3->fetchrow_array())
{
if($row3[2]>$thresh)
{
print "TB,$bsc,$thresh,/$row3[2]";
}
}
}
if($kpi eq "TCHDROP")
{
$sth4->execute($bsc) ||
die "Could not execute SQL statement ... maybe invalid?";
while (my @row4=$sth4->fetchrow_array())
{
if($row4[2]>$thresh)
{
print "TD,$bsc,$thresh,/$row4[2]";
}
}
}
有什么改善表现的想法? 提前谢谢。