作者:化妆师苹苹 | 来源:互联网 | 2023-06-04 21:35
Ihavesomethingthatlookslikethis:我有一些看起来像这样的东西:my$reportnewReportGenerator;#customobj
I have something that looks like this:
我有一些看起来像这样的东西:
my $report = new ReportGenerator; #custom object
my $dbh = $dbc->prepare('SELECT * FROM some_table WHERE some_condition'); #DBI handle
$dbh->execute();
while(my $href = $dbh->fetchrow_hashref){
$report->process_record($href);
}
$dbh->finish();
print $report->printReport();
My problem is that each iteration of the loop is very slow. The problem is the MySQL. I was wondering if it was possible to put some kind of wrapper in the while loop to make it fetch more than one record at a time, at the same time, fetching all records into memory is not practical either. I am not worried about the efficiency of the code(hashref vs arrayref,etc..). Rather, I am interested in fetching lets say 10000 records at a time.
我的问题是循环的每次迭代都很慢。问题是MySQL。我想知道是否有可能在while循环中放置某种包装器以使其一次获取多个记录,同时,将所有记录提取到内存中也是不实际的。我并不担心代码的效率(hashref vs arrayref等)。相反,我有兴趣获取让我们一次说10000条记录。
The database has ~5 Million records. I can not change/upgrade the server.
该数据库有大约500万条记录。我无法更改/升级服务器。
Thanks
谢谢
3 个解决方案