This is just a guess, as I am not sure what bpoStub is. I looked for on CPAN and other places and couldn't find a reference to it, so I am assuming that it's an in-house module.

When I use the DBI module, executing SQL takes two or three steps: creating the SQL, preparing it (I can combine the "create" and "prepare" into one step) and executing it. It looks like you are combining the "prepare" and "execute" steps with bpoStub:

my $D = new bpoStub; . . . $sql = "select DBCompNum from FieldMap where DBTable=\"$DBTable\" and FormID = $FormID group by DBCompNum"; @rowscomp = $D->select($sql); for $countc ( 1 .. $#rowscomp ) { . . . }
If that is the case, I suspect that part of your problem is how you are doing the sql. Consider the following:
use DBI; . . . my $sql = 'INSERT INTO ' . $table . '(title, description, filename, pa +th) VALUES (?, ?, ?)'; my $sth = $dbh->prepare($sql); while ($some_condition) { $sth->execute( $title, $description, $filename, $storagePath ); # do stuff which modifies condition and perhaps # the insertion values }
The question marks (VALUES (?, ?, ?)) in the SQL are placeholders. When it is "prepared", DBI prepares the sql and then inserts whatever values you pass to it with $sth->execute. Because the "prepare" statement has a high overhead, you should never prepare SQL inside of a loop if you can avoid it. It looks like your SQL is static, except for the variables that you pass. If that is the case, prepare all of your SQL outside of the loops you have and execute inside of the loops.

On a side note, I also spotted this regex in a loop:

if ( $Type{$DBCol} =~ /numeric|float|int|money/ ) {...}
That regex will be recompiled every time it is encountered, also increasing your run time. Since it is also static, add the /o modifier to force the regex compiler to compile it only once during the run, thus saving time.

Further, I am guessing that $type{$DBCol} is not likely to have a space prior to the column type. Using ^ at the beginning of the regex will force it to match at the beginning. Otherwise, it will try every character after the first for a match, thus increasing run time.

if ( $Type{$DBCol} =~ /^numeric|float|int|money/o ) {...}
Hope this helps! Cheers.

In reply to Re: Optimization for Speed w HTML to Database processing by Ovid
in thread Optimization for Speed w HTML to Database processing by raflach

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, details, 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, summary, 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.