Optimizing for speed

This is also in the CPAN documentation, but it's probably worth a page here.

If your DBI-based application is slower than you expected you can try the following:

Fix your schema
Check for slow queries (e.g. in mysql client use "show full processlist" or list all the SQL queries and use EXPLAIN if available) and see if you can improve your database schema or add a missing index.

"Lazy population" by Class::DBI
Reduce the amount of data retrieval done by Class::DBI by telling it which columns you need all the time ("Essential") and which columns you don't mind infrequently making an extra SQL query for ("Others"). package MyApplication::Thing; use base 'MyApplication::DBI'; __PACKAGE__->table('thing'); __PACKAGE__->columns(Primary => qw/id/); __PACKAGE__->columns(Essential => qw/name/); __PACKAGE__->columns(Others => qw/colour weight/);

This will increase performance, particularly if this class is on the many side of a one-to-many relationship.