Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

It is my understanding that the purpose of preparing the statement is to reduce the work you are done each iteration. As written, you are preparing the statement each time, which will add a little time to each pass. Perhaps a better way to do this would be:

# Recommend not using '*' but specifying the field names, # to future-proof code. my $query1 = "SELECT * FROM database1.table WHERE ( id = ? );"; my $query2 = "INSERT INTO database2.table ( value1, value2 ) VALUES ( ?, ? ) ;"; my $sth1 = $dbh1->prepare( $query1 ) or die $dbh1->errstr; my $sth2 = $dbh2->prepare( $query2 ) or die $dbh2->errstr; foreach my $id ( @big_data_arrray ) { # Original code had an error # $sth2->execute was called in both cases $sth1->execute( $id ) or die $dbh1->errstr; while ( my @row = $sth1->fetchrow_array ) { $sth2->execute( @row[0 .. 1] ) or die $dbh2->errstr; } $sth1->finish; }

Instead of performing 2*N (N=number of items in @big_data_array) prepare calls, only 2 prepare calls are used.

Hope that helps.


In reply to Re: dbi: moving big data among databases (prepared statements) by atcroft
in thread dbi: moving big data among databases (prepared statements) by leostereo

Title:
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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 09:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found