2012-06-23 5 views
0

downloaded from here 일 수있는 매우 작은 샘플 프로젝트로 작업하고 있습니다. 내가 뭘 하려는지 가져 오는 것은 내 자신의 프로젝트에서 오랜 시간이 걸리는 이유를 디버깅하는 것이지만이 프로젝트를 일종의 벤치 마크로 사용했습니다. -com.apple.CoreData.SQLDebug 1을 내 스키마에서 사용할 수있게되어 어떤 명령어가 내 페치와 함께 SQLite 저장소로 보내지는지 확인할 수 있습니다.코어 데이터 불일치

먼저 AppDelegate에서 for 루프에 첫 번째 부분 (은행이 작성되는 곳)을 포장하여 1000 개의 객체를 만듭니다. AppDelegate에서 가져 오기 요청을 주석 처리합니다.

그런 다음 FBCFMasterViewController에서 가져 오기 요청이 있습니다. 1000 개 항목을 저장 한 후 응용 프로그램을 실행하고 NSFetchedResultsController로 가져 오는되면, 당신은 다음과 비슷한 출력 라인의 수천을 볼 수 있습니다 :

2012-06-23 09:16:30.374 FailedBankCD[90166:fb03] CoreData: annotation: sql connection fetch time: 0.0004s 
2012-06-23 09:16:30.375 FailedBankCD[90166:fb03] CoreData: annotation: total fetch execution time: 0.0009s for 1 rows. 
2012-06-23 09:16:30.375 FailedBankCD[90166:fb03] CoreData: annotation: fault fulfilled from database for : 0xc3e9060 <x-coredata://60E5B64A-83AB-4E6A-BEAD-5FFF50DB7F66/FailedBankDetails/p823> 
2012-06-23 09:16:30.376 FailedBankCD[90166:fb03] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZCLOSEDATE, t0.ZUPDATEDATE, t0.ZZIP, t0.ZINFO FROM ZFAILEDBANKDETAILS t0 WHERE t0.Z_PK = ? 

을 내가 그에서 같은데요하면 sortDescriptor가 초기화되는 것입니다 주요 details.closeDate는 관계이므로, 그 속성에 따라 정렬 할 때 수천 줄의 출력이 나타나도록 각 객체를 in로 가져와야합니다. 더 이상 내가 출력 라인의 수천을 반복하지 않는

2012-06-23 08:53:04.924 FailedBankCD[89564:fb03] CoreData: sql: SELECT 0, t0.Z_PK FROM ZFAILEDBANKINFO t0 ORDER BY t0.ZCITY DESC 
2012-06-23 08:53:04.929 FailedBankCD[89564:fb03] CoreData: annotation: sql connection fetch time: 0.0049s 
2012-06-23 08:53:04.930 FailedBankCD[89564:fb03] CoreData: annotation: total fetch execution time: 0.0059s for 1009 rows. 
2012-06-23 08:53:04.936 FailedBankCD[89564:fb03] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZCITY, t0.ZNAME, t0.ZSTATE, t0.ZDETAILS FROM ZFAILEDBANKINFO t0 WHERE t0.Z_PK IN (?,?,?,?,?,?,?,?,?,?) ORDER BY t0.ZCITY DESC LIMIT 10 
2012-06-23 08:53:04.938 FailedBankCD[89564:fb03] CoreData: annotation: sql connection fetch time: 0.0013s 
2012-06-23 08:53:04.939 FailedBankCD[89564:fb03] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZCLOSEDATE, t0.ZUPDATEDATE, t0.ZZIP, t0.ZINFO FROM ZFAILEDBANKDETAILS t0 WHERE t0.ZINFO IN (?,?,?,?,?,?,?,?,?,?) 
2012-06-23 08:53:04.971 FailedBankCD[89564:fb03] CoreData: annotation: sql connection fetch time: 0.0318s 
2012-06-23 08:53:04.972 FailedBankCD[89564:fb03] CoreData: annotation: total fetch execution time: 0.0326s for 10 rows. 
2012-06-23 08:53:04.973 FailedBankCD[89564:fb03] CoreData: annotation: Prefetching with key 'details'. Got 10 rows. 
2012-06-23 08:53:04.974 FailedBankCD[89564:fb03] CoreData: annotation: total fetch execution time: 0.0372s for 10 rows. 

:

그래서 내가 대신 재산 city에 정렬 할 sortDescriptor을 변경, 내가 실행이 시간, 나는 다음과 같은 출력을 얻을 이는 예상되는 출력으로 보입니다. 심지어 아무것도 수정하지 않고, 다시 실행하는 경우에는, 다시 다음과 같은 출력의 라인 수천 비슷한 얻을 :

2012-06-23 09:19:31.263 FailedBankCD[90216:fb03] CoreData: annotation: sql connection fetch time: 0.0006s 
2012-06-23 09:19:31.264 FailedBankCD[90216:fb03] CoreData: annotation: total fetch execution time: 0.0010s for 20 rows. 
2012-06-23 09:19:31.264 FailedBankCD[90216:fb03] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZCITY, t0.ZNAME, t0.ZSTATE, t0.ZDETAILS FROM ZFAILEDBANKINFO t0 WHERE t0.Z_PK IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ORDER BY t0.ZCITY DESC LIMIT 20 

이 아니, 이상한 행동입니까? 누구든지이 내용을 신속하게 복제하고 진행 상황을 설명하고 수천 줄의 출력을 얻는 이유는 무엇입니까?

+0

결과가 동일합니까? 나는 Core Data가 두절 된 쿼리를 번역 할까봐 걱정하지 않을 것이다. –

답변

1

close_datecity은 색인이 생성되지 않습니다. 이는 수천 개의 쿼리와 낮은 성능을 설명합니다. 달리기의 차이점은 다음과 같습니다.

NSFetchedResultsController *theFetchedResultsController = 
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest 
            managedObjectContext:managedObjectContext sectionNameKeyPath:nil 
               cacheName:@"Root"];