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:
If that is the case, I suspect that part of your problem is how you are doing the sql. Consider the following: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 ) { . . . }
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.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 }
On a side note, I also spotted this regex in a loop:
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.if ( $Type{$DBCol} =~ /numeric|float|int|money/ ) {...}
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.
Hope this helps! Cheers.if ( $Type{$DBCol} =~ /^numeric|float|int|money/o ) {...}
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |