Re: Core Data request predicates and to-many relationships
Re: Core Data request predicates and to-many relationships
- Subject: Re: Core Data request predicates and to-many relationships
- From: "Melissa J. Turner" <email@hidden>
- Date: Mon, 8 Dec 2008 15:17:18 -0800
On Dec 8, 2008, at 14:47, Luke Evans wrote:
Thanks for the reply Melissa - much appreciated.
I was beginning to toy with the idea of trying a function expression
(which I have used before for other purposes) to isolate an
individual attribute object and perform the several comparisons
therein.
Presumably SUBQUERY, being designed for the job, benefits from some
performance advantages over the function approach(?).
Regards
Luke
It depends on the query/dataset. There's no real way to tell until you
run against a sample that's a good approximation the data your
application will be working with. That sounds kind of fluffy, but as
with most things, it's a tradeoff between the time spent doing the
joins and the time it would take to do the fetch differently, which
usually involves additional IO or in-memory computation. Subqueries
are supported natively by CoreData/SQLite, so you do avoid a lot of
the object instantiation you'd be dealing with if you were
postprocessing the potential results (the set of objects without the
correlated subquery) in memory.
Another option is to invert the query: fetch all the destination
objects which meet your criteria for the destination, set the request
to prefetch the relationship you're actually interested in, then do a
second fetch with (targetObjects IN
resultsOfFirstFetch.toMany.@distinctUnionOfSets) and
includesPropertyValues set to NO (the data is already in the row cache
at this point).
Cheers,
+Melissa
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden