[Dbix-class] Q: prefetch has_many relation

Bernhard Graf dbic4 at augensalat.de
Fri Apr 9 15:21:13 GMT 2010


Am 09.04.2010 17:10, schrieb Bernhard Graf:

> Meanwhile I found out, that the resultset attribute "rows" is
> "responsible" for switching to the big SQL code:

Thinking again I realized that this makes pretty much sence.

> my $new_rs = $artist_rs->search(
>     undef, {
>         prefetch => 'cds',
>         rows => 2,
>     }
> );
> 
> [...]
> 
> 
> SELECT me.id, me.name, cds.id, cds.artist_id, cds.title
> FROM (
>   SELECT me.id, me.name
>   FROM artist me
>   GROUP BY me.id, me.name
>   LIMIT 2
> ) me
> LEFT JOIN cd cds ON cds.artist_id = me.id
> ORDER BY cds.artist_id

That way really only two artists are fetched - well done! :)

Is the GROUP BY on all columns useful? Does that affects perfomance?

Bernhard Graf





More information about the DBIx-Class mailing list