Re: CoreData fetch is way too slow
Re: CoreData fetch is way too slow
- Subject: Re: CoreData fetch is way too slow
- From: Phil <email@hidden>
- Date: Tue, 5 Feb 2008 14:52:15 -0500
On Feb 5, 2008, at 2:31 PM, James Hober wrote:
I have a CoreData app that has a SQLite store holding 157,273
managed objects. Each managed object has 2 attributes, input and
answer, which are NSStrings and that's all. No other attributes.
No relationships. No fetched properties.
A simple fetch for a single managed object takes 7 seconds!
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K
like %@",
@"input", input]; //assume NSString *input exists
Two things come to mind:
First, make sure that 'input' is indexed.
Second, be careful of how/when you use 'like' in your predicates as it
is pretty easy to take a huge performance hit (this is true even when
using straight SQL) as you can have a clause that requests "input like
'%sometext'" which can't make use of an index and you'll force a full
table scan.
I found Ben's response to one of my posts a few weeks back quite
helpful: http://www.cocoabuilder.com/archive/message/cocoa/2008/1/16/196552
Phil
_______________________________________________
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