Hot handles
Use prepare() to get a handle on the statement in the SQL cache and keep it there.
The handle for the pre-prepared statement avoids a round-trip to server for cache-check / parsing etc.
Avoid using $dbh->do(…) in a loop.
Use $sth = $dbh->prepare(…)
and $sth->execute() instead.
For example, convert looped do("insert … ?", $id)