Core Data Predicate Performance Problem
Core Data Predicate Performance Problem
- Subject: Core Data Predicate Performance Problem
- From: David Emme <email@hidden>
- Date: Mon, 15 May 2006 07:58:58 -0700
I have constructed a fetch predicate, which
[[request predicate] predicateFormat] confirms is:
ANY r_groupFoods.longDesc LIKE[c] "*egg*milk*" OR ANY
r_groupFoods.longDesc LIKE[c] "*milk*egg*"
Tracing CoreData, I see that the SQL generated is:
CoreData: sql: SELECT DISTINCT 0, F.Z_PK, F.Z_OPT, F.ZFOODGRPCODE,
F.ZFOODGRPDESC FROM ZFOODGROUP F
JOIN ZFOODDESC F1 ON F.Z_PK = F1.ZR_FOODGROUP
JOIN ZFOODDESC F2 ON F.Z_PK = F2.ZR_FOODGROUP
WHERE ( ( NSCoreDataLike( F1.ZLONGDESC, ?, 1)
OR NSCoreDataLike( F2.ZLONGDESC, ?, 1) ) )
ORDER BY F.ZFOODGRPDES
In this case, the second JOIN involving F2 is completely unnecessary. My
database is large, and I allowed the above fetch request to run the
wheels off my CPU for 10 minutes(!) and it still had not completed due
to the excessive combinatorics resulting from the extra JOIN.
Manually typing the SQL that I really need into sqlite3:
sqlite> select distinct * from zfoodgroup f
join zfooddesc f1 on f.z_pk = f1.zr_foodgroup
where (f1.zlongdesc like '%egg%milk%')
or (f1.zlongdesc like '%milk%egg%');
this request ran to completion and returned records in about 2 seconds.
Obviously I can break the NSPredicate into two pieces, one looking for
*A*B* and the other looking for *B*A*, run them separately, then union
the results. But I'd rather be able to do the entire job in a single
CoreData fetch request. Is there some way I can construct a predicate
that CoreData will interpret without the extra JOIN?
TIA,
-Dave
--
For the moment, however, I am most interested in those creatures
who have taken things as they found them and then found out how
to find them good.
- Joseph Wood Krutch
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden