On Jun 23, 2008, at 17:11, Ian wrote:

Hi all,

Anyway, is there any way to query CoreData in chunks? I have a very large CoreData SQl store (>1 million) of managed objects and it's taking for ever (well, tens of minutes) to load it all in, never mind to search through it all.

NSFetchRequest has a very handy setFetchLimit selector but it's fairly useless (to my particular problem anyhow) without being able to specify an offset.

Being able to say "give me the first 10000 rows" is cool and all, but not being able to say "give me the NEXT 10000 rows" is a real pain.

I know CoreData is supposed to be able to handle billions (citation: http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdPerformance.html [search page text for "billions"]) of rows, but seriously, I'm not getting these results. Any more than a few tens of thousands of results and it's slow down city.

The problem is that Core Data doesn't use rows -- it doesn't have any intrinsic ordering of objects (that's why unsorted results are always sets, not arrays). There's no general concept of the "next" 10000 objects.

To query in chunks, you need to implement your own concept of ordering (which may or may not be easy, depending on your requirements). For example, if you can allocate each object a sequence number (as a permanent attribute), you could use a sequence number range as part of each potentially large fetch. If you turn on indexing for the attribute, there should be no significant performance degradation dependent on which range you fetch.

Obviously, a simple sequence number is not a good solution if many objects can be randomly deleted. There's likely no good *general* solution for all applications, which is (AFAIK) the reason Core Data doesn't yet offer intrinsic ordering of objects. Another possibly workable attribute might be date/time of object creation, date/time of object modification, or a random hash of something like the object UID.


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to