My table in the CoreData has like 8 columns, all are strings. The largest string's length is less than 10K.
First, I use the following codes to retrieve the rows:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"Item" inManagedObjectContext:context]];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"(URL ==[c] %@)", url]];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Time" ascending:NO selector:nil];
NSArray *descriptors = [NSArray arrayWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:descriptors];
[sortDescriptor release];
NSError *error = nil;
NSArray *array = [context executeFetchRequest:fetchRequest error:&error];
Here is the performance log:
2011-05-10 11:47:18.743 Test2[2176:5907] CoreData: annotation: sql connection fetch time: 2.6172s
2011-05-10 11:47:21.600 Test2[2176:5907] CoreData: annotation: total fetch execution time: 2.8577s for 144 rows.
144 rows for more than 2 secs?
Then I construct an non-coredata object for each row:
if ([array count] > 0) {
for (Item *item in array) {
SimpleItem *sitem = [[SimpleItem alloc] init];
sitem.Title = item.Title;
sitem.Summary = item.Summary;
sitem.URL = item.URL;
[dataDict setObject:sitem forKey:item.URL];
[sitem release];
}
[dataDict release];
}
part of The performance log ( i think for one row read) for the above codes is:
2011-05-10 11:47:21.617 Test2[2176:5907] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZURL, t0.ZSUMMARY, , t0.ZIMAGEURL, t0.ZTITLE, t0.ZURL, t0.ZTIME FROM ZITEM t0 WHERE t0.Z_PK = ?
2011-05-10 11:47:21.629 Test2[2176:5907] CoreData: annotation: sql connection fetch time: 0.0098s
2011-05-10 11:47:21.633 Test2[2176:5907] CoreData: annotation: total fetch execution time: 0.0162s for 1 rows.
It seems faults are there.
Anyone can help me to improve the performance?
Also, I have checked "Index" option for URL when I edit the data model in xcode. Is that enough for setting up an index?