Get the best performance out of CoreData

26 Mar
2010

Small change, BIG impact. Remember there’s SQLite sitting under your wrapper. So don’t do chained OR’s.

An expression like ”

x='A' OR x='B'

” will not make use of an index on column x. Instead use ”

x IN ('A', 'B')

“.

Whoops. Changed and now queries run *much* quicker. (with an index on the uid)

See the SQLite optimization FAQ and the guide about NSPredicate

As a bonus, i changed my code from 6 to just one line :)

NSArray *dbUsers = [self usersWithPredicate:[NSPredicate predicateWithFormat:@"account=%@ AND uid IN %@", [self currentAccount], uids]];

Related posts:

  1. Diving into CoreData, again
  2. CoreData and mergeChangesFromContextDidSaveNotification

Comment Form

top

Switch to our mobile site