[Dbix-class] totally simplified example of my prefetch problem.

Matt S Trout dbix-class at trout.me.uk
Mon Aug 14 20:50:58 CEST 2006


George Hartzell wrote:
> Matt S Trout writes:
>  > George Hartzell wrote:
>  > > I've put together a dead-simple example that demonstrates the problem
>  > > that I'm having using prefetch.  Three tables, 4 rows of data in
>  > > total, simple driver script, etc....
>  > 
>  > You can only prefetch one "direction" of has_many rels at once. Anything else 
>  > results in a cross-product return of records which tends to be heinously 
>  > inefficient anyway.
>  > 
>  > i.e.
>  > 
>  > [ 'hm_rel', 'other_hm_rel' ] won't work
>  > 
>  > although
>  > 
>  > [ { 'hm_rel' => { 'belongs_to_rel' => 'ya_hm_rel' }, 'other_belongs_to_rel' ]
>  > 
>  > and similar are fine.
>
> Ok.
>
> So, working with the example that I posted, what's the most effecient
> thing to do if you want to get back an "A" and all that goes with it?
>
> Sounds like I just have to pick whether I'm more likely to monkey with
> the A's b's or c's and just prefetch one or the other.
Or you can run one query that prefetches one and one that prefetches the 
other.

Or use search_related across the entire set to get all the rows for 
t'other one back

Or whatever.

I'd love to have more options here, but at the moment I've not run into 
a situation where it hurt our performance enough to do so, and nobody 
else seems to have either.



More information about the Dbix-class mailing list