sgifford has asked for the wisdom of the Perl Monks concerning the following question:
I'm doing a query that returns many rows, using DBI and DBD::mysql. I expect the $sth->execute to get the query started and return almost immediately, and then one of the fetchrow methods to actually get the results. Instead, execute seems to gather all of the results before returning, taking a long time to finish and using up over 1GB of memory.
Is there a way to work around this?
Here's my code. It gets to "Executing..." and then sits there for a very long time taking up memory; based on other tests it will eventually return, and after that the fetchrows will work.
#!/usr/bin/perl -w BEGIN { $ENV{MYSQL_UNIX_PORT}='/clair8/corpora/aledb/run/socket'; }; use strict; use DBI; my $sql = "SELECT url1.urlid AS from_id, url1.url AS from_url, link1.l +ink_text AS link1_text, link1.linkid AS link1_id, url2.urlid AS to_id +, url2.url AS to_url FROM DOTGOV_links AS link1, DOTGOV_urls AS url1, DOTGOV_urls AS url2 WHERE (link1.link_from = url1.urlid) AND (link1.link_to = url2.urlid)"; warn "Connecting...\n"; my $dbh = DBI->connect('DBI:mysql:database=clair', 'root','', {AutoCom +mit => 1}) or die "Error creating dbh.\n"; warn "Connected!\n"; warn "Preparing...\n"; my $sth = $dbh->prepare($sql) or die "Error preparing sth.\n"; warn "Prepared!\n"; warn "Executing...\n"; $sth->execute or die "Error executing sth.\n"; warn "Executed!\n"; warn "Finishing...\n"; $sth->finish or die "Error finishing sth.\n"; warn "Finished!\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: DBI/mysql gathering all rows on execute
by gmax (Abbot) on Nov 24, 2003 at 20:39 UTC | |
by sgifford (Prior) on Nov 24, 2003 at 21:17 UTC | |
Re: DBI/mysql gathering all rows on execute
by talexb (Chancellor) on Nov 24, 2003 at 20:12 UTC | |
by jdtoronto (Prior) on Nov 24, 2003 at 20:33 UTC | |
Re: DBI/mysql gathering all rows on execute
by VSarkiss (Monsignor) on Nov 24, 2003 at 20:44 UTC | |
by Anonymous Monk on Nov 25, 2003 at 08:04 UTC | |
Re: DBI/mysql gathering all rows on execute
by princepawn (Parson) on Nov 24, 2003 at 20:08 UTC |
Back to
Seekers of Perl Wisdom