T
Thomas Götz
hi there,
I have the following problem:
I'm using a MySQL database with a table that contains around 500.000
records. If I now want to select all that rows to do something with them,
this is getting _very_ memory-consuming.
Here's the code I use:
---------
#!/usr/bin/perl -w
use strict;
use warnings;
use DBI;
my $dsn = "DBI:mysql:SOME_DATABASE:localhost";
my $user = "tom";
my $pwd = "*********";
my $dbh = DBI->connect($dsn, $user, $pwd) or die;
my $sql = qq{SELECT `SOME_FIELD` ` FROM `SOME_TABLE`};
my $sth = $dbh->prepare($sql);
$sth->execute;
while (my $result = $sth->fetchrow_array) {
print "$result\n";
}
$sth->finish;
$dbh->disconnect;
exit;
---------
So, when executing the statement it seems that all result are loaded into
memory before they are processed, which is not what I want. What could I do
to speed up things and become less memory hungry?
Tom
I have the following problem:
I'm using a MySQL database with a table that contains around 500.000
records. If I now want to select all that rows to do something with them,
this is getting _very_ memory-consuming.
Here's the code I use:
---------
#!/usr/bin/perl -w
use strict;
use warnings;
use DBI;
my $dsn = "DBI:mysql:SOME_DATABASE:localhost";
my $user = "tom";
my $pwd = "*********";
my $dbh = DBI->connect($dsn, $user, $pwd) or die;
my $sql = qq{SELECT `SOME_FIELD` ` FROM `SOME_TABLE`};
my $sth = $dbh->prepare($sql);
$sth->execute;
while (my $result = $sth->fetchrow_array) {
print "$result\n";
}
$sth->finish;
$dbh->disconnect;
exit;
---------
So, when executing the statement it seems that all result are loaded into
memory before they are processed, which is not what I want. What could I do
to speed up things and become less memory hungry?
Tom