CoreData에서 약 수백 개의 레코드를 가져 와서 categories_id로 분류하여 섹션에 넣어야합니다. 아래는 페치 레코드의 수백 느린 받아 들일 약 1.5 초 걸리는 fetchedResultControllerCoreData 및 그룹 분류 기준에서 가져 오기가 매우 느립니다.
- (NSFetchedResultsController *)fetchedResultsController
{
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%d == mall_id",self.mallId.intValue];
NSFetchRequest *fetch = [[NSFetchRequest alloc] initWithEntityName:@"Shop"];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"category_id" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
[fetch setPredicate:predicate];
[fetch setFetchBatchSize:20];
[fetch setSortDescriptors:sortDescriptors];
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetch managedObjectContext:self.contextForDb sectionNameKeyPath:@"category_id" cacheName:@"root"];
return self.fetchedResultsController;
}
에 대한 코드입니다. 며칠 동안 인터넷에서 검색을 시도했지만이 성능 문제를 해결하지 못했습니다.
병목 목은 데이터베이스의 그룹화라고 생각합니다.
누군가 도와주세요.
UPDATE
2012-04-02 17:57:08.872 SGMalls[186:707] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZADDRESS, t0.ZID, t0.ZLATITUDE, t0.ZLONGITUDE, t0.ZNAME, t0.ZPHONE, t0.ZUPDATED_TIME, t0.ZURL, t0.ZZIP FROM ZMALL t0 WHERE t0.ZID = ?
2012-04-02 17:57:08.875 SGMalls[186:707] CoreData: annotation: sql connection fetch time: 0.0030s
2012-04-02 17:57:08.877 SGMalls[186:707] CoreData: annotation: total fetch execution time: 0.0047s for 1 rows.
2012-04-02 17:57:09.040 SGMalls[186:707] CoreData: sql: SELECT 0, t0.Z_PK FROM ZSHOP t0 WHERE ? = t0.ZMALL_ID ORDER BY t0.ZCATEGORY_ID
2012-04-02 17:57:09.390 SGMalls[186:707] CoreData: annotation: sql connection fetch time: 0.3496s
2012-04-02 17:57:09.391 SGMalls[186:707] CoreData: annotation: total fetch execution time: 0.3514s for 16 rows.
2012-04-02 17:57:09.395 SGMalls[186:707] CoreData: sql: SELECT t0.ZCATEGORY_ID, COUNT (DISTINCT t0.Z_PK) FROM ZSHOP t0 WHERE ? = t0.ZMALL_ID GROUP BY t0.ZCATEGORY_ID ORDER BY t0.ZCATEGORY_ID
2012-04-02 17:57:09.741 SGMalls[186:707] CoreData: annotation: sql connection fetch time: 0.3458s
2012-04-02 17:57:09.743 SGMalls[186:707] CoreData: annotation: total fetch execution time: 0.3475s for 3 rows.
2012-04-02 17:57:09.748 SGMalls[186:707] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZDETAIL, t0.ZID, t0.ZNAME FROM ZCATEG t0 WHERE t0.ZID = ?
2012-04-02 17:57:09.751 SGMalls[186:707] CoreData: annotation: sql connection fetch time: 0.0028s
2012-04-02 17:57:09.754 SGMalls[186:707] CoreData: annotation: total fetch execution time: 0.0061s for 1 rows.
2012-04-02 17:57:09.757 SGMalls[186:707] Title: icon_foodspecialties
2012-04-02 17:57:09.765 SGMalls[186:707] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZDETAIL, t0.ZID, t0.ZNAME FROM ZCATEG t0 WHERE t0.ZID = ?
2012-04-02 17:57:09.767 SGMalls[186:707] CoreData: annotation: sql connection fetch time: 0.0022s
2012-04-02 17:57:09.769 SGMalls[186:707] CoreData: annotation: total fetch execution time: 0.0042s for 1 rows.
2012-04-02 17:57:09.773 SGMalls[186:707] Title: icon_supermarket
2012-04-02 17:57:09.782 SGMalls[186:707] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZDETAIL, t0.ZID, t0.ZNAME FROM ZCATEG t0 WHERE t0.ZID = ?
2012-04-02 17:57:09.784 SGMalls[186:707] CoreData: annotation: sql connection fetch time: 0.0022s
2012-04-02 17:57:09.787 SGMalls[186:707] CoreData: annotation: total fetch execution time: 0.0046s for 1 rows.
SQL 디버깅 콘솔 가게 엔티티 관계가 있습니까
모델의 어딘가에 색인을 설정 했습니까? –
예 category_id에 인덱스를 설정했으나 아무런 효과가 없습니다. –
좋습니다. 같은 fetchRequest가 느린 것인가요? 이제 정렬을 생략 할 때가 되었습니까? mall_id에 대한 색인이 있습니까? –