[Dbix-class] HasDetails comments

Todd Holbrook paradawks at gmail.com
Fri Jul 29 17:56:43 CEST 2005


On 7/28/05, Matt S Trout <dbix-class at trout.me.uk> wrote:
> On Thu, Jul 28, 2005 at 04:47:13PM -0700, Todd Holbrook wrote:
> > <snip />
> 
> Hmm, is there any reason why the DBIx::Class version shouldn't use a
> composite PK on 'movie' and 'field', given you're treating them as
> kinda-sorta-columns anyway?

Nope, the "details" are not repeating fields so a composite PK would
suffice.  I didn't want to get into that with CDBI, so it has a single
PK in that version.

> The thing is, might_have smells to me like an updatable view, and so does this.
> The select would be like -
> 
> SELECT movies.id as id, movies.title as title, movies.year as year,
>  tagline.value as tagline, genre.value as genre, price.value as price
> FROM movies
>   LEFT JOIN movie_details tagline
>     ON movies.id = tagline.movie AND details_1.field = 'tagline'
>   ...
> WHERE movies.id = ?
 
Yep, that's pretty much what the query would boil down to.  Given that
these are generally not core fields that are used alot (in my usage
anyway), it might be worth evaluating whether a big join query would
be more efficient than lazy loading them as a group when one is
accessed.  There's probably a break even point where optimizing and
executing a query with possibly 10s of LEFT JOINS would be slower than
a simple query that brings back all details columns associated with a
record and loads them at once.
 
Todd
--
Todd Holbrook
Systems Consultant
Simon Fraser University



More information about the Dbix-class mailing list