
SEL for count?
Reported by Tony Pitale | July 27th, 2009 @ 05:00 PM
Associations seem to be eager-loading when all that is required is a count. This can take awhile when the count of rows is even in the 10k+ area, if not more.
Comments and changes to this ticket
-
Martin Gamsjaeger (snusnu) July 30th, 2009 @ 07:57 PM
- State changed from new to confirmed
-
Tony Pitale August 2nd, 2009 @ 10:49 PM
- Tag changed from aggregates, associations, count, sel to aggregates, associations, count, failing, sel, spec
First stab at a dm-aggregates failing spec patch. Not sure it can be made to pass from within dm-aggregates.
-
Tony Pitale August 3rd, 2009 @ 12:14 AM
The problem may be with DataMapper::Collection#delegate_to_relationship which does not create a lazyarray or something like it. At that point, it fully builds the collection from the relationship before anything (e.g., count) is ever done to it. It would seem that the only time we would actually want to load something when we want to do something with it.
-
Tony Pitale August 3rd, 2009 @ 12:26 AM
This is probably not news to anyone but me, however, SEL is used regardless of whether or not the association in a loop is ever used for anything. That's obviously an affect of the association not being a lazyarray when called.
-
Tony Pitale August 4th, 2009 @ 08:09 AM
- Tag changed from aggregates, associations, count, failing, sel, spec to aggregates, associations, core, count, failing, sel, spec
Here is a potential change to dm-core that fixes my original gist. It changes the spec and Collection to lazy load for #delegate_to_relationship. This ends up breaking the many_to_many spec in a way I have yet to understand, but I will post up anyway.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »