There's more than one way to do things | |
PerlMonks |
Re^3: How to improve MYSQL search performance of perl?by CountZero (Bishop) |
on Aug 19, 2005 at 18:32 UTC ( [id://485259]=note: print w/replies, xml ) | Need Help?? |
I see why it is so slow: you are effectively for every search opening a connection, doing the search for 1 item and then destroying the connection. All this connecting and disconnecting is very time-consuming. You should put your connection stuff in an initialization subroutine, then prepare your SQL-statement once, using place-holders as follows: " my $sth = $dbh->prepare('select topic FROM table1 WHERE uri LIKE ?');" (added benefit: you don't have to worry about quoting!) and then hand off the $sth-variable and the search-argument to your search-subroutine which calls the execute-method with the search string as its parameter:
Do you get the idea! CountZero "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
In Section
Seekers of Perl Wisdom
|
|