sqlite Indexing Performance Advice

后端 未结 4 1021
广开言路
广开言路 2020-12-10 09:32

I have an sqlite database in my iPhone app that I access via the Core Data framework. I\'m using NSPredicates to query the database.

I am building a search function

4条回答
  •  一生所求
    2020-12-10 10:04

    From the Core Data Programming Guide:

    How you use predicates can significantly affect the performance of your application. If a fetch request requires a compound predicate, you can make the fetch more efficient by ensuring that the most restrictive predicate is the first, especially if the predicate involves text matching (contains, endsWith, like, and matches) since correct Unicode searching is slow. If the predicate combines textual and non-textual comparisons, then it is likely to be more efficient to specify the non-textual predicates first, for example (salary > 5000000) AND (lastName LIKE 'Quincey') is better than (lastName LIKE 'Quincey') AND (salary > 5000000).

    If there is a way to reorder your query such that the simplest logic is on the left, and the most complex on the right, that can help your search performance. As Lyon suggests, searching Unicode text is extremely expensive, so Apple recommends searching against derived values that strip unicode characters and common phrases like a, and, and the.

提交回复
热议问题