[Dbix-class] Prefetch question

Bernhard Graf dbic4 at augensalat.de
Wed Dec 16 16:43:54 GMT 2009


Prefetching is a convenient thing, but may also need a lot of resources.

E.g. I have a users table, that belongs_to("country"). Table 'country'
has more information (e.g. full name, int. phone code, time zones, etc).

The users table may have zillions of rows, whereas the the country table
is quite small (and nearly all users belong to a handful of countries).


With prefetching I get the same country data over and over again.
Without prefetching DBIC delays country fetches until I access
$user->country, but then also fetches the same country data all the time.

Is it possible not to prefetch country, but tell DBIC to cache delayed
fetches of related data, so that each related country row is really only
fetched once for this user resultset?

Or can I read the whole country table first and then somehow assign
those rows to the appropriate $user->rows?


Bernhard Graf



More information about the DBIx-Class mailing list