我正在使用 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]";
}
}
}
有什么想法可以提高性能吗?提前致谢。