[CDBI] Retrieving Columns Other then Essentials

Nigel Metheringham nigel.metheringham at dev.intechnology.co.uk
Fri Mar 17 17:31:56 GMT 2006


On Fri, 2006-03-17 at 11:16 -0600, Scott Kahler wrote:
> Class DBI new user here.  I'm trying to follow this example from the
> man page:
> 
> snip
>        You should therefore group together your columns by typical
> usage, as fetching one value from a group can also pre-fetch all the
> others in that
>        group for you, for more efficient access.
> 
>        So for example, if we usually fetch the artist and title, but
> don't use the 'year' so much, then we could say the following:
> 
>          Music::CD->columns(Primary   => qw/cdid/);
>          Music::CD->columns(Essential => qw/artist title/);
>          Music::CD->columns(Others    => qw/year runlength/);
> 
>        Now when you fetch back a CD it will come pre-loaded with the
> 'cdid', 'artist' and 'title' fields. Fetching the 'year' will mean
> another visit to
>        the database, but will bring back the 'runlength' whilst it's
> there.
> 
>        This can potentially increase performance.
> snip
> 
> My question is how exactly do I fetch the year after I've made a call
> such as
> 
> my $cd_obj =Music::CD->retrieve(1);
> 
> I'm probably missing something very obvious but I can't seem to find
> it.

Its as easy as...
	$cd_obj->year

CDBI will generate another SQL query to grab the missing data if it was
not loaded originally.

This is *much* slower than the original slow down in loading all the
columns instead of just some, so if there is anything other than a
vanishingly small chance of requiring that extra data or some other good
reason for not doing so (like the extra data is huge - blobs etc) then
its probably best to just stuff it all into Essential.

	Nigel.
-- 
[ Nigel Metheringham           Nigel.Metheringham at InTechnology.co.uk ]
[ - Comments in this message are my own and not ITO opinion/policy - ]






More information about the ClassDBI mailing list