Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (5)
    As of 2020-01-22 03:14 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?