Check your DB index usage… MySQL's
EXPLAIN is your friend.
LOCK TABLES &
never call a subroutine.
Check the DB error code after a SQL statement. Just because it worked once and the SQL is correct, that doesn't mean the table might not go corrupt, a disk might fill up, or index space within the file might not fill up. Errors happen. Deal with them.
Preferred way to break up a long SQL query:
$sth = $dbh->prepare("SELECT cola, colb, colc, cold FROM foo ". "WHERE colb<>cola AND colc=22");
Note on variable naming:
||one database handle (usually the master)|
||set of database handles [master(, slave)]|
||read-only slave db handle (used for selects)|
||argument that can take a
||hashref of remote user, based on cookies. will contain 'userid' and 'user' params.|
||a user 'object' (a hashref)|
Call for database handles as you need them, instead of predeclaring
LJ::get_db_writer to get a writable handle to the database, and
LJ::get_db_reader to get a read-only handle.