Reputation: 359
I am using NSFetchResultsController
to receive items from database (there are 80.000 items).
This is my predicate: @"(desc CONTAINS[cd] %@)", [any text]
And for NSFetchRequest
I set next properties:
request.propertiesToFetch = [NSArray arrayWithObject:[[entityDescription propertiesByName] objectForKey:@"icd"]];
request.returnsDistinctResults = YES;
[request setFetchBatchSize:100];
[request setSortDescriptors:[NSArray arrayWithObject:[[NSSortDescriptor alloc] initWithKey:@"icd" ascending:YES]]];
The idea behind this is that I want a live search (every character user writes in a textfield, the NSFetchResultsController
should fetch into database again.
The problem is next: on iPad Mini, every fetch duration is between 2-3 seconds, which is very very much. I remember that I did same thing now 1 years ago, and worked faster.
Can you please give me some advice? I really don't know how to improve query.
Upvotes: 0
Views: 45
Reputation: 28419
Your problem is your predicate. It causes a scan of every record to find which ones contain the desired search text. Furthermore, using [cd] makes it even slower.
This exact problem is addressed in the 2013 WWDC presentation on Core Data Performance.
Upvotes: 1