sqlite Indexing Performance Advice

后端 未结 4 1026
广开言路
广开言路 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:07

    There are things you can do to improve the performance of searching for text in sqlite databases. Although Core Data abstracts you away from the underlying store it can be good to have an appreciation of what is going on when your store is backed using sqlite.

    If we assume you're doing a substring search of these fields there are things you can do to improve search performance. Apple recommend using a derived properties. This amounts to maintaining a normalised version of your property in your model that is used for searching. The derived property should be done in a way that it can be indexed. You then express your search in terms of this derived property using binary operators > <= etc.

    I found doing this reduced our search from around 1 second to under 100ms.

    To make things clear I would suggest looking at the ADC example http://developer.apple.com/mac/library/samplecode/DerivedProperty/

提交回复
热议问题