I meant for eager. In the case of eager. You would prefetch say 100 records at a time. Then get the assocations for those using foreign keys. So you would still have let's the main query + 2 associations = 3 total queries vs potentially N queries right?
So I'm guess you have kind of just preload them with as_hash and manually append it into your paged_each call I suppose you can do something like Model.order(:a).enum_for(:paged_each, options).each_slice... And then for each slice go and ge the associations, but wouldn't it just be easier to call all in the paged-each code (assuming you are using eager). I agree, probably with eager_graph all bets are off... On Monday, July 3, 2017 at 7:59:26 PM UTC-7, Jeremy Evans wrote: > > On Monday, July 3, 2017 at 6:30:04 PM UTC-7, Aryk Grosz wrote: >> >> Hi Jeremy, I think I might PR that. Would love to contribute. >> >> In addition to this, I noticed in your paged_each code you do not call >> "all" after applying the limit and offset. Wouldn't this bypass calling >> #eager and then paged_each? >> >> Any reason for this? How do you recommend I get the benefits of eager >> with paged_each? >> > > You can't really eager load without getting all records up front.. Having > paged_each do eager loading would result in N/S queries per association, > where N is the number of rows and S the number for rows per page. It could > partially work for #eager, but definitely could not work for #eager_graph. > > If you are iterating over the entire dataset, you can do: > > id_map = AssociatedClass.as_hash > MainClass.paged_each do |row| > row.associations[:association_name] = id_map[row[:key_column]] # > many_to_one > end > > or similar things for other association types. > > Thanks, > Jeremy > -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
