Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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";

In reply to DBI/mysql gathering all rows on execute by sgifford

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2023-06-03 12:14 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (14 votes). Check out past polls.